In ASP.Net 2.0, GridView Control also provides the functionality to edit and update the data retrieved from the database using CommandField template. You can cancel the action using Cancel Command of the CommandField. GridView consists of events that can be used to perform the actions like edit, update and cancel upon the Data items displayed in the ASP.Net GridView Data Control. RowUpdating, RowEditing and RowCancelingEdit events enable you to bind the relevant actions to perform the GridView Edit, Update and Cancel commands. If GridView Control has Id="GridView1" then it generates the following event Handlers for these commands:
You can generate these events for the specified GridView control by double clicking on the event names in the Property View for Events associated with GridView.
In this tutorial for GridView Edit Update and Cancel Command we have used categories table of Northwind SQL Database. To start with first of all you have to create a Data Binding function for the GridView. Data Binding function is also required to reset the Mode of the GridView each time when the event of edit, update or cancel is fired by the user. In the sample C# code with this tutorial we have created a data binding function bindGridView(). To set the GridView mode to default or edit mode you can use the following code:
{
GridView1.EditIndex = e.NewEditIndex;
bindGridView();
}
GridView1.EditIndex = -1;
GridView.EditIndex property sets or resets the mode of row at the specified index to edit view or read only view.
Learn about ASP.Net GridView Update Command in next tutorial and download the free source code for GridView Edit Update and Cancel command there.
Currently rated 5.0 by 2 people
Tags: asp.net 2.0, c#, asp.net gridview, asp.net gridview edit, asp.net gridview commandfield, asp.net gridview update, asp.net gridview cancel, asp.net gridview rowediting, asp.net gridview rowcancelingedit, asp.net gridview rowupdating, asp.net gridview edit mode, asp.net gridview templatefield, asp.net gridview itemtemplate, asp.net gridview edititemtemplate, c# gridview, c# code
9/25/2008 8:32:43 AM
Good one. This article solve my imp problem. thanx
prasad j
10/11/2008 3:32:42 AM