System.Web.UI.WebControls Namespace GridView Class
.NET Framework version 2.0
Occurs when a Delete command button within a GridView control is clicked, but after the delete operation.
[ VB ]
Public Event RowDeleted As GridViewDeletedEventHandler
[ C# ]
public event GridViewDeletedEventHandler RowDeleted;
[ C++ ]
public: __event GridViewDeletedEventHandler* RowDeleted;
In [ JScript ], you can handle the events defined by a class, but you cannot define your own.
The RowDeleted event is raised whenever a Delete button associated with an item in the GridView control is clicked, but after the GridView control deletes the record.
This allows you to provide an event-handling method that performs a custom routine, such as checking the results of a delete operation, whenever this event occurs.
Information related to the RowDeleted event is passed via a GridViewDeletedEventArgs object to the method assigned to handle the event. The following GridViewDeletedEventArgs properties provide information specific to this event.
Property |
Description |
AffectedRows |
Gets the number of rows affected by the delete operation. |
Exception |
Gets the exception ( if any ) that was raised during the delete operation. |
ExceptionHandled |
Gets or sets a value indicating whether an exception that was raised during the delete operation was handled in the event handler. |
Keys |
Gets an ordered dictionary of key field name/value pairs for the deleted record. |
Values |
Gets a dictionary of the non-key field name/value pairs for the deleted record. |
The following example demonstrates how to use the RowDeleted event to determine whether an exception occurred during a delete operation.
<script language = "C#" runat = "server">
void EmployeeGridView_RowDeleted ( Object src, GridViewDeletedEventArgs e ) {
// Use the Exception property to determine whether
// an exception occurred during the delete operation.
if ( e.Exception == null ) {
// Use the AffectedRows property to determine whether the record was deleted.
// Sometimes an error might occur but does not raise an exception,
// yet prevents the delete operation from completing.
if ( e.AffectedRows == 1 ) {
MessageLabel.Text = "Record deleted successfully.";
} else {
MessageLabel.Text = "An error occurred during the delete operation.";
}
} else {
// Insert the code to handle the exception.
MessageLabel.Text = e.Exception.Message;
// Use the ExceptionHandled property to indicate
// that the exception has already been handled.
e.ExceptionHandled = true;
}
}
</script>
<script language = "VB" runat = "server">
Sub EmployeeGridView_RowDeleted ( ByVal src As Object, ByVal e As GridViewDeletedEventArgs )
' Use the Exception property to determine whether
' an exception occurred during the delete operation.
If e.Exception Is Nothing Then
' Use the AffectedRows property to determine whether the record was deleted.
' Sometimes an error might occur but does not raise an exception,
' yet prevents the delete operation from completing.
If e.AffectedRows = 1 Then
MessageLabel.Text = "Record deleted successfully."
Else
MessageLabel.Text = "An error occurred during the delete operation."
End If
Else
' Insert the code to handle the exception.
MessageLabel.Text = e.Exception.Message
' Use the ExceptionHandled property to indicate
' that the exception has already been handled.
e.ExceptionHandled = True
End If
End Sub
</script> |
|
C# |
VB |
GridView Members Allowing Users to Delete Rows in a GridView Control