Display the details of the GridView Row being Deleted and Cancel the delete operation

The GridView.RowDeleting event occurs when a GridView row's Delete button is clicked, but before the GridView control deletes the row. Handling this event helps you to display details of the row, cancel the delete operation or to perform some checks before the row is deleted.

C#

protected void GV_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int ID = (int)GV.DataKeys[e.RowIndex].Value;
// If you want to cancel the delete operation, you
// can do so by saying e.Cancel = true;
}

VB.NET

Protected Sub GV_RowDeleting(ByVal sender As Object, _
ByVal e As GridViewDeleteEventArgs)
Dim ID As Integer = CInt(GV.DataKeys(e.RowIndex).Value)
' If you want to cancel the delete operation, you
' can do so by saying e.Cancel = true;
End Sub

A GridViewDeleteEventArgs object is passed to the event-handling method, which enables you to determine the index of the current row as well as cancel the delete operation, as shown in the code above.



Will you give this article a +1 ? Thanks in advance


About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal

No comments: