title: how to get value of textbox created dynamically in gridview asp.net
body: <p>I want to count such rows which have textbox.text !=null with external button click but when I try row.findcontrol its null here is my code</p>
  
  <pre><code>    &lt;asp:GridView ID="GridViewCellNo" runat="server" AutoGenerateColumns="False" BorderStyle="None"
  GridLines="None" OnRowDataBound="GridViewAddCellNumber_RowDataBound" ShowFooter="True"
  ShowHeader="false"&gt;
  &lt;Columns&gt;
  &lt;asp:TemplateField ItemStyle-Width="200px"&gt;
  &lt;ItemTemplate&gt;
  &lt;asp:Label ID="LabelGVCellRowNo" runat="server" Text='&lt;%#Eval("CellRowNumber")%&gt;'
  Visible="false"&gt;&lt;/asp:Label&gt;
  &lt;asp:TextBox ID="TextBoxCellNo" runat="server" Text='&lt;%#Eval("CellNumber")%&gt;' Width="350px"&gt;&lt;/asp:TextBox&gt;
                                                          &lt;asp:RegularExpressionValidator ID="REVCellNumber" runat="server" ControlToValidate="TextBoxCellNo"
                                                              CssClass="ErroreMessage" Display="None" ErrorMessage="&amp;lt;b&amp;gt;Required Field Missing&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Please enter the phone number(digits only)."
                                                              SetFocusOnError="True" ValidationExpression="^[0-9]*$"&gt;&lt;/asp:RegularExpressionValidator&gt;
                                                          &lt;asp:ValidatorCalloutExtender ID="VCOE_REVPhoneNumber" runat="Server" HighlightCssClass="validatorCalloutHighlight"
  TargetControlID="REVCellNumber"&gt;
  &lt;/asp:ValidatorCalloutExtender&gt;
   &lt;/ItemTemplate&gt;
   &lt;FooterTemplate&gt;
   &lt;asp:TextBox ID="TextBoxAddCellNum" runat="server" Width="350px"&gt;&lt;/asp:TextBox&gt;                                                   
  &lt;asp:RegularExpressionValidator ID="REVCellNumber" runat="server" ControlToValidate="TextBoxAddCellNum"                                                     CssClass="ErroreMessage" Display="None" ErrorMessage="&amp;lt;b&amp;gt;Required Field Missing&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Please enter the phone number(digits only)."
  SetFocusOnError="True" ValidationExpression="^[0-9]*$"&gt;&lt;/asp:RegularExpressionValidator&gt;
  &lt;asp:ValidatorCalloutExtender ID="VCOE_REVPhoneNumber" runat="Server" HighlightCssClass="validatorCalloutHighlight"
  TargetControlID="REVCellNumber"&gt;
  &lt;/asp:ValidatorCalloutExtender&gt;
  &lt;/FooterTemplate&gt;
   &lt;/asp:TemplateField&gt;
   &lt;asp:TemplateField FooterStyle-HorizontalAlign="left" ItemStyle-HorizontalAlign="left"
   ItemStyle-Width="200px" ShowHeader="False"&gt;                                        
   &lt;FooterTemplate&gt;
    &lt;table&gt;
    &lt;tr&gt;
   &lt;td width="20px"&gt;
    &lt;/td&gt;
  &lt;td&gt;
   &lt;asp:Button ID="addAttributeGridViewCellNoButtonAdd" runat="server" CausesValidation="true" Text="+" OnClick="GridViewAddCellNumberButtonAdd_Click" ToolTip="Add" ValidationGroup="AddCellNo" Width="30px" OnClientClick="showProgress()"  /&gt;
   &lt;/td&gt;
    &lt;td&gt;
   Add another number
    &lt;/td&gt;
    &lt;/tr&gt;
    &lt;/table&gt;
   &lt;/FooterTemplate&gt;
    &lt;/asp:TemplateField&gt;
    &lt;/Columns&gt;
    &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>When I run this function below on a button click event it gives txtCellno =null</p>
  
  <pre><code>private int GridViewCellNoCount()
      {
          int cellCount = 0;
          foreach (GridViewRow row in GridViewCellNo.Rows)
          {
              TextBox txtCellno = row.FindControl("TextBoxAddCellNum") as TextBox;
  
              //if (((TextBox)row.FindControl("TextBoxAddCellNum")).Text.Length &gt; 0)
              if (txtCellno.Text.Length &gt; 0)
              {
                  cellCount++;
              }
  
          }
          return cellCount;
  </code></pre>