System.Web.UI.WebControls Namespace FormView Class
.NET Framework version 2.0
Occurs when a Delete command button within a FormView control is clicked, but after the delete operation.
[ VB ]
Public Event ItemDeleted As FormViewDeletedEventHandler
[ C# ]
public event FormViewDeletedEventHandler ItemDeleted;
[ C++ ]
public: __event FormViewDeletedEventHandler* ItemDeleted;
In [ JScript ], you can handle the events defined by a class, but you cannot define your own.
The ItemDeleted event is raised whenever a Delete button associated with an item in the FormView control is clicked, but after the FormView 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 ItemDeleted event is passed via a FormViewDeletedEventArgs object to the method assigned to handle the event. The following FormViewDeletedEventArgs 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 ItemDeleted event to determine whether an exception occurred during a delete operation.
<script language = "C#" runat = "server">
void EmployeeFormView_ItemDeleted ( Object src, FormViewDeletedEventArgs 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 EmployeeFormView_ItemDeleted ( ByVal src As Object, ByVal e As FormViewDeletedEventArgs )
' 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 |
FormView Members Allowing Users to Delete Items in a FormView Control