January 17, 2010

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.



'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP 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 has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

0 Responses to "Display the details of the GridView Row being Deleted and Cancel the delete operation"
 

Copyright © 2009-2012 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions