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