Follow the steps:
1. Add the footer templates to gridview(i.e. Textbox, Dropdown and ImageButton).
<columns>
<asp:templatefield headertext="Test" xmlns:asp="#unknown">
<itemtemplate>
....
</itemtemplate>
<footertemplate>
<asp:textbox id="Textbox1" runat="server" />
</footertemplate>
</asp:templatefield>
</columns>
2. Assign the CommandName Property of ImageButton to "Add".
<columns>
<asp:templatefield headertext="Test" xmlns:asp="#unknown">
<itemtemplate>
....
</itemtemplate>
<footertemplate>
<asp:imagebutton id="ImgBtn" runat="server" commandname="Add" />
</footertemplate>
</asp:templatefield>
</columns>
3. Handle RowCommand event of GridView.
protected void GridView1_OnRowCommand1(object sender, GridViewCommandEventArgs e)
{
}
4. Check for the CommandName property.
protected void GridView1_OnRowCommand1(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("Add"))
{
}
}
5. Find the footer control and do your operation.
protected void GridView1_OnRowCommand1(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("Add"))
{
TextBox sp = GridView1.FooterRow.FindControl("Textbox1") as TextBox;
DropDownList dT = GridView1.FooterRow.FindControl("DropDown1") as DropDownList;
}
}
See a demo
here[
^].
--Amy