asp.net.ph

FormView.ItemUpdated Event

System.Web.UI.WebControls Namespace   FormView Class


.NET Framework version 2.0

Occurs when an Update command button within a FormView control is clicked, but after the update operation.

[ VB ]
Public Event ItemUpdated As FormViewUpdatedEventHandler

[ C# ]
public event FormViewUpdatedEventHandler ItemUpdated;

[ C++ ]
public: __event FormViewUpdatedEventHandler* ItemUpdated;

In [ JScript ], you can handle the events defined by a class, but you cannot define your own.

Remarks

The ItemUpdated event is raised whenever an Update button associated with an item in the FormView control is clicked, but after the FormView 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.

Event Data

Information related to the ItemUpdated event is passed via a FormViewUpdatedEventArgs object to the method assigned to handle the event. The following FormViewUpdatedEventArgs 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 FormView 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.

Example

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 EmployeeFormView_ItemUpdated ( Object src, FormViewUpdatedEventArgs 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>
  C# VB

See Also

FormView Members   Allowing Users to Edit Rows in a FormView Control Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph