title: Get footer row cell values of gridview
body: <p>I have a gridview with two textboxes in the footer. What's required is get the textbox values, store it to a datatable and then bind the same to the gridview. 
  I am unable to get the textbox values. They show up empty (as you can see). Where am I going wrong.</p>
  
  <p><img src="https://i.stack.imgur.com/Mvvvj.jpg" alt="enter image description here"></p>
  
  <p>ASPX:</p>
  
  <pre><code>&lt;asp:GridView ID="gv" runat="server" AutoGenerateColumns="False" 
  ShowFooter="true" OnRowDataBound="gv_RowDataBound"  
  OnRowCommand="gv_RowCommand"&gt;           
   &lt;Columns&gt;
    &lt;asp:TemplateField&gt;
     &lt;ItemTemplate&gt;
      &lt;asp:LinkButton ID="lnkEdit" runat="server" Text="Edit" CommandName="Edit"&gt;
  &lt;/asp:LinkButton&gt;
    &lt;/ItemTemplate&gt;
    &lt;EditItemTemplate&gt;
     &lt;asp:LinkButton ID="lnkUpdate" runat="server" Text="Update" 
  CommandName="Update"&gt;&lt;/asp:LinkButton&gt;
     &amp;nbsp;&lt;asp:LinkButton ID="lnkCancel" runat="server" Text="Cancel"  
     CommandName="Cancel"&gt;&lt;/asp:LinkButton&gt;
     &lt;/EditItemTemplate&gt;
     &lt;/asp:TemplateField&gt;
     &lt;asp:TemplateField HeaderText="S.No"&gt;
       &lt;ItemTemplate&gt;
         &lt;%#Container.DataItemIndex %&gt;
       &lt;/ItemTemplate&gt;
       &lt;/asp:TemplateField&gt;
       &lt;asp:TemplateField HeaderText="ID"&gt;
         &lt;ItemTemplate&gt;
         &lt;asp:Label ID="lbId" runat="server" Text='&lt;%#Eval("id") %&gt;'&gt;&lt;/asp:Label&gt;
         &lt;/ItemTemplate&gt;
      &lt;EditItemTemplate&gt;
       &lt;asp:TextBox ID="txtId" runat="server" Text='&lt;%#Eval("id") %&gt;'&gt;
       &lt;/asp:TextBox&gt;
       &lt;/EditItemTemplate&gt;
       &lt;FooterTemplate&gt;
       &lt;asp:TextBox ID="txtNewId" runat="server"&gt;&lt;/asp:TextBox&gt;
      &lt;asp:RequiredFieldValidator runat="server" ControlToValidate="txtNewId" 
       SetFocusOnError="true"
      ErrorMessage="*" ForeColor="Red"&gt;&lt;/asp:RequiredFieldValidator&gt;
      &lt;/FooterTemplate&gt;
      &lt;/asp:TemplateField&gt;
      &lt;asp:TemplateField HeaderText="NAME"&gt;
      &lt;ItemTemplate&gt;
      &lt;asp:Label ID="lbName" runat="server" Text='&lt;%#Eval("name") %&gt;'&gt;&lt;/asp:Label&gt;
      &lt;/ItemTemplate&gt;
      &lt;EditItemTemplate&gt;
       &lt;asp:TextBox ID="txtName" runat="server" Text='&lt;%#Eval("name") %&gt;'&gt;
       &lt;/asp:TextBox&gt;
        &lt;/EditItemTemplate&gt;
        &lt;FooterTemplate&gt;
       &lt;asp:TextBox ID="txtNewName" runat="server"&gt;&lt;/asp:TextBox&gt;
       &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
        ControlToValidate="txtNewName" SetFocusOnError="true" 
        ErrorMessage="*" ForeColor="Red"&gt;&lt;/asp:RequiredFieldValidator&gt;
       &lt;/FooterTemplate&gt;
       &lt;/asp:TemplateField&gt;
       &lt;asp:TemplateField&gt;
       &lt;ItemTemplate&gt;
       &lt;asp:LinkButton ID="lnkDelete" runat="server" Text="Delete" 
        CommandName="Delete"&gt;&lt;/asp:LinkButton&gt;
       &lt;/ItemTemplate&gt;
       &lt;FooterTemplate&gt;
       &lt;asp:LinkButton ID="lnkInsert" runat="server" Text="Insert" 
         CommandName="Insert" &gt;&lt;/asp:LinkButton&gt;                    
       &lt;/FooterTemplate&gt;
       &lt;/asp:TemplateField&gt;
       &lt;/Columns&gt;
      &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>CS:</p>
  
  <pre><code>protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
      {
          DataTable dt = new DataTable();
  
          switch (e.CommandName)
          {
              case "Insert":
                  GridViewRow fRow = gv.FooterRow;
                  dt.Columns.Add("id");
                  dt.Columns.Add("name");
                  dt = (DataTable)ViewState["students"];
                  DataRow dr = dt.NewRow();
                  dr["id"] = ((TextBox)fRow.FindControl("txtNewId")).Text;
                  dr["name"] = ((TextBox)fRow.FindControl("txtNewName")).Text;
                  dt.Rows.Add(dr);
                  ViewState["students"] = dt;
                  gv.DataSource = ViewState["students"];
                  gv.DataBind();
                  break;
          }
      }
  </code></pre>
  
  <p>The textboxes are txtNewId, txtNewName.</p>