Please refer this code
Ref:
I have added the Footer Template in the Child GridView.
Here is the changed HTML of GridView
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" CssClass="Grid"
DataKeyNames="CustomerID" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img alt="" style="cursor: pointer" src="images/plus.png" />
<asp:Panel ID="pnlOrders" runat="server" Style="display: none">
<asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid"
ShowFooter="true">
<Columns>
<%-- <asp:BoundField ItemStyle-Width="150px" DataField="OrderId" HeaderText="Order Id" />
<asp:BoundField ItemStyle-Width="150px" DataField="OrderDate" HeaderText="Date" />--%>
<asp:TemplateField HeaderText="Order Id">
<ItemTemplate>
<asp:Label ID="lblOrderId" Text='<%# Eval("OrderId") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtOrderId" Text='<%# Eval("OrderId") %>' runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OrderDate">
<ItemTemplate>
<asp:Label ID="lblOrderDate" Text='<%# Eval("OrderDate") %>' runat="server" />
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtOrderDate" Text='<%# Eval("OrderDate") %>' runat="server"></asp:TextBox>
<asp:LinkButton Text="Add" OnClick="AddRows" runat="server" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="150px" DataField="ContactName" HeaderText="Contact Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="City" HeaderText="City" />
</Columns>
</asp:GridView>
C#
Onclick event of LinkButton. After saving the data i have refreshed the page to populate the added data.
protected void AddRows(object sender, EventArgs e)
{
GridViewRow row = (sender as LinkButton).NamingContainer as GridViewRow;
string orderId = (row.FindControl("txtOrderId") as TextBox).Text.Trim().Replace(",", "");
string orderDate = (row.FindControl("txtOrderDate") as TextBox).Text.Trim().Replace(",", "");
//Write code here to save these two variable data in SQL table
Response.Redirect(Request.Url.AbsoluteUri);
}
Screenshot
