title: How to findcontrol of template gridview within a gridview?
body: <p>i have a problem getting the control of my second grid("StaffAppraisalGrid"). It shows null whenever i run the code <strong>GridView staffGrid = (GridView)SubmitAppraisalGrid.FindControl("StaffAppraisalGrid");</strong>
  . What could be the problem?</p>
  
  <p>design:</p>
  
  <pre><code> &lt;asp:GridView ID="SubmitAppraisalGrid" runat="server" AutoGenerateColumns="False" ShowHeader="False" BorderWidth="0px"&gt;
      &lt;Columns&gt;
          &lt;asp:TemplateField&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="QuestionLbl" runat="server" Text='&lt;%# Bind("Question")%&gt;'&gt;&lt;/asp:Label&gt;
                  &lt;asp:GridView ID="StaffAppraisalGrid" runat="server" AutoGenerateColumns="False"&gt;
                      &lt;Columns&gt;
                          &lt;asp:BoundField DataField="StaffName"/&gt;
                          &lt;asp:TemplateField&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:RadioButtonList ID="RadioList" runat="server" DataSource='&lt;%# Bind("RadioButtonList")%&gt;'&gt;
                                  &lt;/asp:RadioButtonList&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
                          &lt;asp:TemplateField&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:TextBox ID="RemarksTbx" runat="server" Text='&lt;%# Bind("RemarkTbx")%&gt;'&gt;&lt;/asp:TextBox&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
                      &lt;/Columns&gt;
                  &lt;/asp:GridView&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>sample code:</p>
  
  <pre><code>                ArrayList listofquestion= dbmanager.GetAllQuestion();
  
              ArrayList listofstaff = dbmanager.GetAllStaffName();
              DataTable dt = new DataTable();
              DataRow dr = null;
              dt.Columns.Add(new DataColumn("Question", typeof(string)));
  
              foreach (Question ques in listofquestion)
              {
                  dr = dt.NewRow();
                  dr["Question"] = "Q"+ques.QuestionID + ") " + ques.QuestionDetails+"?";
                  dt.Rows.Add(dr);
              }
  
              ViewState["QuestionTable"] = dt;
  
              //staffgrid
              int index = 0;
              for (int i = 0; i &lt; dt.Rows.Count; i++)
              {
                  DataTable staffdt = new DataTable();
                  DataRow staffdr = null;
                  staffdt.Columns.Add(new DataColumn("StaffName", typeof(string)));
                  staffdt.Columns.Add(new DataColumn("RadioButtonList", typeof(ArrayList)));
                  staffdt.Columns.Add(new DataColumn("RemarkTbx", typeof(string)));
                  ArrayList listofradio = new ArrayList();
                  listofradio.Add("1");
                  listofradio.Add("2");
                  listofradio.Add("3");
                  listofradio.Add("4");
                  listofradio.Add("5");
                  listofradio.Add("6");
                  listofradio.Add("7");
                  listofradio.Add("N/A");
  
                  foreach (string staffname in listofstaff)
                  {
                      staffdr = staffdt.NewRow();
                      staffdr["StaffName"] = staffname;
                      staffdr["RadioButtonList"] = listofradio;
                      staffdr["RemarkTbx"] = string.Empty;
                      staffdt.Rows.Add(staffdr);
                  }
                  GridView staffGrid = (GridView)SubmitAppraisalGrid.FindControl("StaffAppraisalGrid");
                  ViewState["QuestionTable"] = staffdt;
                  staffGrid.DataSource = staffdt;
                  staffGrid.DataBind();
                  index++;
              }
              //before bind
              SubmitAppraisalGrid.DataSource = dt;
              SubmitAppraisalGrid.DataBind();
  </code></pre>