title: Hide/show table in gridview on button click event
body: <p>I have project on recruitment.In this project, at one form I have a grid view which contains details of all vacancies. Along with this there is button. When user clicks on this button, available interview schedule for that particular vacancy will be visible in another grid below that row. What I did is I have placed grid view inside table and table is initially invisible. When user clicks on the image button, at that time I tried to find table from the grid view but it can not be found. 
  Here is the code of my .aspx page</p>
  
  <pre><code>&lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"&gt;
  &lt;table class="formtTbl" width="100%"&gt;
      &lt;tr&gt;
          &lt;td width="10%"&gt;
              &amp;nbsp;
          &lt;/td&gt;
          &lt;td&gt;
              &amp;nbsp;&lt;/td&gt;
          &lt;td width="10%"&gt;
              &amp;nbsp;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &amp;nbsp;&lt;/td&gt;
          &lt;td align="center" class="tdtitle"&gt;
              Open vacancies
          &lt;/td&gt;
          &lt;td&gt;
              &amp;nbsp;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &amp;nbsp;&lt;/td&gt;
          &lt;td&gt;
          &lt;asp:ImageButton ID="addVacancyBtn" runat="server" 
              ImageUrl="~/Resources/add.png" onclick="addVacancyBtn_Click" /&gt;
              &amp;nbsp;
              Add New Vacancy&lt;/td&gt;
          &lt;td&gt;
              &amp;nbsp;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &amp;nbsp;&lt;/td&gt;
          &lt;td&gt;
              &lt;asp:GridView ID="VacancyGrid" runat="server" CssClass="mGrid" 
                  AutoGenerateColumns="False" onrowcommand="VacancyGrid_RowCommand"&gt;
                  &lt;AlternatingRowStyle CssClass="alt" /&gt;
                  &lt;Columns&gt;
                   &lt;asp:TemplateField&gt;
                       &lt;ItemTemplate&gt;
                          &lt;asp:ImageButton ID="ScheduleBtn" runat="server" 
                           ImageUrl="~/Resources/01.gif"  
                           ToolTip="View Interview Schedule" Width="20px"
                           CommandName="View Schedule" CommandArgument="&lt;%#((GridViewRow)Container).RowIndex %&gt;"/&gt;
                       &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:BoundField HeaderText="VacId" DataField="VacId" /&gt;
                      &lt;asp:BoundField HeaderText="Title" DataField="VacTitle" /&gt;
                      &lt;asp:BoundField HeaderText="Open" DataField="TotalOpening" /&gt;
                      &lt;asp:BoundField HeaderText="Criteria" DataField="criteria" /&gt;
                      &lt;asp:BoundField HeaderText="Key Skills" DataField="KeySkills" /&gt;
                      &lt;asp:BoundField HeaderText="Exp" DataField="RequiredExperience" /&gt;
                      &lt;asp:TemplateField&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:ImageButton ID="editBtn" runat="server" 
                                  ImageUrl="~/Resources/art-knife.png" Width="20px" 
                                  CommandName="Edit" CommandArgument="&lt;%#((GridViewRow)Container).RowIndex %&gt;"/&gt;
                          &lt;/ItemTemplate&gt;
                          &lt;EditItemTemplate&gt;
                              Edit
                          &lt;/EditItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Label ID="statusLbl" runat="server" Text="Label"&gt;&lt;/asp:Label&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField&gt;
                          &lt;ItemTemplate&gt;
                          &lt;table id="ScheduleTable" visible="false"&gt;
                          &lt;tr id="abc" visible="false"&gt; 
                            &lt;td colspan="10"&gt;
                              &lt;asp:GridView ID="scheduleGrid" runat="server" Visible="False" 
                                    AutoGenerateColumns="False" onrowcommand="scheduleGrid_RowCommand"&gt;
                              &lt;Columns&gt;
                              &lt;asp:BoundField DataField="VacId" HeaderText="ID" /&gt;
                             &lt;asp:BoundField DataField="VacTitle" HeaderText="Title" /&gt;
                              &lt;asp:BoundField DataField="InterviewTime" HeaderText="Interview Date &amp; Time" /&gt;
                                  &lt;asp:TemplateField&gt;
                                      &lt;ItemTemplate&gt;
                                          &lt;asp:ImageButton ID="viewIntervieweesBtn" runat="server" 
                                              ImageUrl="~/Resources/document.png" ToolTip="View interiviewees" Width="20px" 
                                              CommandName="View Interviewees" CommandArgument="&lt;%#((GridViewRow)Container).RowIndex %&gt;"/&gt;
                                      &lt;/ItemTemplate&gt;
                                  &lt;/asp:TemplateField&gt;
                              &lt;/Columns&gt;
                              &lt;/asp:GridView&gt;
                              &lt;asp:Label ID="ScheduleNotifyLbl" runat="server" Visible="false"&gt;&lt;/asp:Label&gt;
                             &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;/table&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                  &lt;/Columns&gt;
                  &lt;PagerStyle CssClass="pgr" /&gt;
              &lt;/asp:GridView&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &amp;nbsp;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &amp;nbsp;&lt;/td&gt;
          &lt;td align="left"&gt;
              &lt;asp:Label ID="notificationLbl" runat="server" Font-Size="X-Large" 
                  ForeColor="Red" Text="Label" Visible="False"&gt;&lt;/asp:Label&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &amp;nbsp;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &amp;nbsp;&lt;/td&gt;
          &lt;td&gt;
              &amp;nbsp;&lt;/td&gt;
          &lt;td&gt;
              &amp;nbsp;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>//Here is the code for my .aspx.cs page</p>
  
  <pre><code>public partial class Department_VacancyList : System.Web.UI.Page
  {
  protected void Page_Load(object sender, EventArgs e)
  {
      DataTable VacancyTable = null;
      try
      {
          if (!IsPostBack)
          {
              if (Request.QueryString["status"] != null)
              {
                  // strStatus = Request.QueryString["status"];
                  Session.Add("strStatus", Request.QueryString["status"]);
              }
              if (Session["OpResult"] != null)
              {
                  notificationLbl.Visible = true;
                  if (Session["OpResult"].ToString() == "InsertSuceess")
                      notificationLbl.Text = "New Vacancy Has Been Created Successfully";
                  if (Session["OpResult"].ToString() == "InsertFail")
                      notificationLbl.Text = "An Error Occured While Creating New Vacancy..";
                  if (Session["OpResult"].ToString() == "EditSuccess")
                      notificationLbl.Text = "Your Changes Has Been Saved Successfully";
                  if (Session["OpResult"].ToString() == "EditFail")
                      notificationLbl.Text = "An Error Occured While Saving Changes...";
              }
              using (VacancyMasterClass VacMaster = new VacancyMasterClass())
              {
                  if (Session["strStatus"].ToString() == "1")//All Vacancies
                      VacancyTable = VacMaster.getTable("and DeptId=1 and CompId=1");//Change Here.
                  else if (Session["strStatus"].ToString() == "2")//Open Vacancies
                      VacancyTable = VacMaster.getTable("and DeptId=1 and CompId=1 and Status=0");//Change Here.
                  else if (Session["strStatus"].ToString() == "3")//Closed Vacancies
                      VacancyTable = VacMaster.getTable("and DeptId=1 and CompId=1 and Status=1");//Change Here.
                  VacancyGrid.DataSource = VacancyTable;
                  VacancyGrid.DataBind();
                  VacancyGrid.ControlStyle.Width = 650;
                  VacancyGrid.Columns[0].ItemStyle.Width = 20;
                  VacancyGrid.Columns[1].ItemStyle.Width = 10;
                  VacancyGrid.Columns[2].ItemStyle.Width = 150;
                  VacancyGrid.Columns[3].ItemStyle.Width = 20;
                  VacancyGrid.Columns[4].ItemStyle.Width = 190;
                  VacancyGrid.Columns[5].ItemStyle.Width = 190;
                  VacancyGrid.Columns[6].ItemStyle.Width = 20;
                  VacancyGrid.Columns[7].ItemStyle.Width = 30;
                  VacancyGrid.Columns[8].ItemStyle.Width = 30;
                  VacancyGrid.Columns[9].ItemStyle.Width = 0;
                  VacancyGrid.Columns[1].Visible = false;
                  if (Session["strStatus"].ToString() == "1" || Session["strStatus"].ToString() == "3")
                  {
                      VacancyGrid.Columns[7].Visible = false;
                      VacancyGrid.Columns[0].Visible = false;
                      for (int intRowcount = 0; intRowcount &lt; VacancyTable.Rows.Count; intRowcount++)
                      {
                          Label StatusLbl = (Label)VacancyGrid.Rows[intRowcount].Cells[6].FindControl("statusLbl");
                          if (VacancyTable.Rows[intRowcount]["Status"].ToString() == "False")
                          {
                              StatusLbl.ForeColor = Color.Green;
                              StatusLbl.Text = "Open";
                          }
                          else
                          {
                              StatusLbl.ForeColor = Color.Red;
                              StatusLbl.Text = "Closed";
                          }
                      }
                  }
                  else if (Session["strStatus"].ToString() == "2")
                      VacancyGrid.Columns[8].Visible = false;
              }      
          }
      }
      catch (Exception ex)
      {
          CommonProcedures.WriteErrorLog("Department_VacancyList", "Page_Load", ex.Message);
      }
      finally
      {
          Session.Remove("OpResult");
      }
  }
  //protected void VacancyGrid_RowEditing(object sender, GridViewEditEventArgs e)
  //{
  //    int intOpMode = 2;//Edit Mode
  //    int intVacId = Convert.ToInt32(VacancyGrid.Rows[e.NewEditIndex].Cells[1].Text);
  //    Response.Redirect("create_vacancyfrm.aspx?VacId="+intVacId+"&amp;OpMode="+intOpMode);
  //}
  protected void addVacancyBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
  {
      int intOpMode = 1;//Edit Mode
      int intVacId = 0;
      Response.Redirect("create_vacancyfrm.aspx?DeptId=1&amp;CompId=1&amp;VacId=" + intVacId + "&amp;OpMode=" + intOpMode);//Change Here
  }
  protected void VacancyGrid_RowCommand(object sender, GridViewCommandEventArgs e)
  {
      DataTable InterviewScheduleTable = null;
      int intVacid = 0;
      try
      {
          if (e.CommandName == "View Schedule")
          {
  
              int intRowIndex = Convert.ToInt32(e.CommandArgument);
              GridViewRow Row = VacancyGrid.Rows[intRowIndex];
              //Table ScheduleTable = (Table)Row.FindControl("ScheduleTable");
              intVacid = Convert.ToInt32(Row.Cells[1].Text);
              GridView scheduleGrid = (GridView)Row.FindControl("scheduleGrid");
              Label ScheduleNotifyLbl = (Label)Row.FindControl("ScheduleNotifyLbl");
  
              if (scheduleGrid.Visible == false)
              {
                  using (vwVacInterviewShcedule oInterviewSchedule = new vwVacInterviewShcedule())
                  {
                      InterviewScheduleTable = oInterviewSchedule.getTable("and VacId=" + intVacid);
                      if (InterviewScheduleTable.Rows.Count &gt; 0)
                      {
                          scheduleGrid.Visible = true;
                          scheduleGrid.DataSource = InterviewScheduleTable;
                          scheduleGrid.DataBind();
                          scheduleGrid.ControlStyle.Width = 650;
                          scheduleGrid.Columns[0].ItemStyle.Width = 10;
                          scheduleGrid.Columns[1].ItemStyle.Width = 300;
                          scheduleGrid.Columns[2].ItemStyle.Width = 250;
                          scheduleGrid.Columns[3].ItemStyle.Width = 90;
                      }
                      else
                      {
                          if (ScheduleNotifyLbl.Visible == false)
                          {
                              ScheduleNotifyLbl.Visible = true;
                              ScheduleNotifyLbl.Text = "Interview is yet to schedyule for this vacancy";
                          }
                          else
                          {
                              ScheduleNotifyLbl.Visible = false;
                          }
                      }
                  }
              }
              else
              {
                  scheduleGrid.Visible = false;
              }
  
          }
          ViewState.Add("VacId", intVacid);
          if (e.CommandName == "Edit")
          {
              int intOpMode = 2;
              int intRowIndex = Convert.ToInt32(e.CommandArgument);
              GridViewRow Row = VacancyGrid.Rows[intRowIndex];
              int intVacId = Convert.ToInt32(Row.Cells[1].Text);
              Response.Redirect("create_vacancyfrm.aspx?VacId=" + intVacId + "&amp;OpMode=" + intOpMode);
          }
      }
      catch (Exception ex)
      {
          CommonProcedures.WriteErrorLog("Department_VacancyList", "VacancyGrid_RowCommand", ex.Message);
      }
      finally
      {
          InterviewScheduleTable = null;
      }
  }
  
   protected void scheduleGrid_RowCommand(object sender, GridViewCommandEventArgs e)
   {
      try
      {
          foreach (GridViewRow Row in VacancyGrid.Rows)
          {
              GridView ScheduleGrid = (GridView)Row.FindControl("scheduleGrid");
              if (e.CommandName == "View Interviewees")
              {
                  int intRowIndex = Convert.ToInt32(e.CommandArgument);
                  GridViewRow ScheduleGridRow = ScheduleGrid.Rows[intRowIndex];
                  int intVacId = Convert.ToInt32(ScheduleGridRow.Cells[3].Text);
                  Session.Add("Time",ScheduleGridRow.Cells[2].Text);
                  Response.Redirect("~/Department Head/Schedulefrm.aspx?VacId="+intVacId);
              }
          }
      }
      catch (Exception ex)
      {
          CommonProcedures.WriteErrorLog("Department_VacancyList", "scheduleGrid_RowCommand", ex.Message);
        }
     }
  }
  </code></pre>
  
  <p>Please show me my problem...</p>