ASP.Net Gridview Edit Update Cancel Commands

by top54u.com 14 Jul, 2008

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:

 

  • protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)

  • protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)

  • protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)

 

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:

 

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)

{

GridView1.EditIndex = e.NewEditIndex;

bindGridView();

}

 

 

protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)

{

GridView1.EditIndex = -1;

bindGridView();

}

 

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.

Comments

9/25/2008 8:32:43 AM

prasad j

Good one. This article solve my imp problem. thanx

prasad j in

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

10/11/2008 3:32:42 AM




related videos.....
recent posts.....
top54u ezines.....