How to add a new row in the GridView control by using the GridView Footer Template
In this article we will see how to add a new row in the GridView control by using the GridView footer template. Steps to add a new row in the GridView control by using the GridView footer template are:Declare <FooterTemplate> element within the TemplateField element which is used for adding a new record in the GridView control. Within the <FooterTemplate>, define the server control which is used to accept new data.
The below code demonstrates how to use <FooterTemplate> and how to add DropDownList in the <FooterTemplate> of the GridView control. The Grid View control displays DropDownList control for selecting new accounts.
<FooterTemplate> <asp:dropdownlist ID="add_aname" DataSourceID="ObjectDataSource1" DataTextField ="AccountName" runat="server"> </asp:DropDownList> </FooterTemplate>
After the above steps are completed, write the Event handler for the GridView RowCommand event. In the Event handler program the following.
Add a new row to the DataTable. Retrieve the values of controls (DropDownList and TextBox controls) which are in the Footer Template. Assign the values entered by the user to the row and assign the row to the DataTable.
protected void grdAccounts_RowCommand(object sender, GridViewCommandEventArgs e) { DataRow rw = dt.NewRow(); DropDownList DDB = (DropDownList)grdAccounts.FooterRow.Cells[0]. FindControl("add_aname"); int sdf = DDB.SelectedIndex; if (txt1.Text != "") { rw[0] = DDB.SelectedValue; dt.Rows.Add(rw); }}
For a detailed explanation of how to add a new row in the GridView control by using the GridView footer template, refer the title :Develop ERP software using ASP.Net 3.5 and C#.
GridView Articles
- GridView AutoGenerateColumns property
- Bind GridView control with SqlDataSource control
- DataBinding in a GridView control
- Binding a GridView programmatically with dataset
- Binding a GridView programmatically with Generic List Collection
- Using fields with the GridView control
- Adding Boundfields to a GridView control
- Adding button fields to a GridView control
- Create Templatefields in a GridView control
- Access a value using SelectedIndexChanged() event when a row in a GridView is selected
- How to restrict an item from being selected using GridView SelectedIndexChanging Event
- Gridview datakeynames
- How to select a particular row in a GridView control using SelectedDataKey method
- Formatting GridView control with CSS
- GridView rowDataBound event
Become an Expert
Learn More
Q1. What is Azure Platform?
GridView CommandField example
GridView and DetailsView Master/Detail page using SqlDataSource control
POCO overview and advantages - POCO class, Entity Framework in Enterprise Applications
Query entity data model using linq to entities
Difference between arraylist and list collection
How to create a Web service using Visual Studio.net
FormView DataBound Event
Calling base class constructor in C#
Convert a sequence to a generic list using ToList()method
ERP Software Development
Project ideas for students
Accounting Software
Creating an ASP.Net MVC 3 application
Using assemblies in .net applications
How to implement form validation using ASP.Net 2.0 Validation Controls
Constructors in Visual Basic.Net
GridView CommandField example
GridView and DetailsView Master/Detail page using SqlDataSource control
POCO overview and advantages - POCO class, Entity Framework in Enterprise Applications
Query entity data model using linq to entities
Difference between arraylist and list collection
How to create a Web service using Visual Studio.net
FormView DataBound Event
Calling base class constructor in C#
Convert a sequence to a generic list using ToList()method
ERP Software Development
Project ideas for students
Accounting Software
Creating an ASP.Net MVC 3 application
Using assemblies in .net applications
How to implement form validation using ASP.Net 2.0 Validation Controls
Constructors in Visual Basic.Net