asp.net.ph

DetailsView.ItemInserted Event

System.Web.UI.WebControls Namespace   DetailsView Class


.NET Framework version 2.0

Occurs when an Insert command button within a DetailsView control is clicked, but after the insert operation.

[ VB ]
Public Event ItemInserted As DetailsViewInsertedEventHandler

[ C# ]
public event DetailsViewInsertedEventHandler ItemInserted;

[ C++ ]
public: __event DetailsViewInsertedEventHandler* ItemInserted;

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

Remarks

The ItemInserted event is raised whenever an Insert button associated with an item in the DetailsView control is clicked, but after the DetailsView control inserts the record.

This allows you to provide an event-handling method that performs a custom routine, such as checking the results of an insert operation, whenever this event occurs.

Event Data

Information related to the ItemInserted event is passed via a DetailsViewInsertedEventArgs object to the method assigned to handle the event. The following DetailsViewInsertedEventArgs properties provide information specific to this event.

Property Description
AffectedRows Gets the number of rows affected by the insert operation.
Exception Gets the exception ( if any ) that was raised during the insert operation.
ExceptionHandled Gets or sets a value indicating whether an exception that was raised during the insert operation was handled in the event handler.
KeepInInsertMode Gets or sets a value indicating whether the DetailsView control should remain in insert mode after an insert operation.
Values Gets a dictionary of the non-key field name/value pairs for the inserted record.

Example

The following example demonstrates how to use the ItemInserted event to determine whether an exception occurred during an insert operation.

<script language = "C#" runat = "server">

   void EmployeeDetailsView_ItemInserted ( Object src, DetailsViewInsertedEventArgs e ) {
      // Use the Exception property to determine whether 
      // an exception occurred during the insert operation.
      if ( e.Exception == null ) {
         // Use the AffectedRows property to determine whether the record was inserted.
         // Sometimes an error might occur but does not raise an exception,
         // yet prevents the insert operation from completing.
         if ( e.AffectedRows == 1 ) {
            MessageLabel.Text = "Record inserted successfully.";
         } else {
            MessageLabel.Text = "An error occurred during the insert operation.";
            // Use the KeepInInsertMode property to remain in insert mode
            // when an error occurs during the insert operation.
            e.KeepInInsertMode = true;
         }
      } 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>
  C# VB

See Also

DetailsView Members   Allowing Users to Add Rows in a DetailsView 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