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.






About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

No comments: