<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" OnRowDeleting="GridView1_RowDeleting" ShowFooter="True"> <Columns> <asp:TemplateField HeaderText="empid"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("empid") %>'></asp:TextBox> </EditItemTemplate> <FooterTemplate> <asp:TextBox ID="footertxtid" runat="server"></asp:TextBox> </FooterTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("empid") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="name"> <EditItemTemplate> <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("empname") %>'></asp:TextBox> </EditItemTemplate> <FooterTemplate> <asp:TextBox ID="footertxtname" runat="server"></asp:TextBox> </FooterTemplate> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("empname") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField ShowHeader="False"> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Add" Text="Add"></asp:LinkButton> </ItemTemplate> <FooterTemplate> <asp:LinkButton ID="footerlnksave" runat="server" Text="Save" CommandName="Save"></asp:LinkButton> </FooterTemplate> </asp:TemplateField> </Columns> </asp:GridView>
if (e.CommandName == "Add") { GridView1.FooterRow.Visible = true; } else if(e.CommandName=="Save") { TextBox txtid = (TextBox)GridView1.FooterRow.FindControl("footertxtid"); int id = Convert.ToInt32(txtid.Text); TextBox txtname = (TextBox)GridView1.FooterRow.FindControl("footertxtname"); string name = Convert.ToString(txtname.Text); }SqlCommand cmd = new SqlCommand("insert into emp values(id,name)",con);con.Open();cmd.ExecuteNonQuery();con.Close();bindgrid();//in bindgrid write GridView1.FooterRow.Visible =false;}