DetailsViewInsertedEventArgs Class
Collapse the table of content
Expand the table of content

DetailsViewInsertedEventArgs Class


Provides data for the ItemInserted event.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)


public class DetailsViewInsertedEventArgs : EventArgs

System_CAPS_pubmethodDetailsViewInsertedEventArgs(Int32, Exception)

Initializes a new instance of the DetailsViewInsertedEventArgs class.


Gets the number of rows affected by the insert operation.


Gets the exception (if any) that was raised during the insert operation.


Gets or sets a value indicating whether an exception that was raised during the insert operation was handled in the event handler.


Gets or sets a value indicating whether the DetailsView control should remain in insert mode after an insert operation.


Gets a dictionary that contains the field name/value pairs for the inserted record.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Creates a shallow copy of the current Object.(Inherited from Object.)


Returns a string that represents the current object.(Inherited from Object.)

The DetailsView control raises the ItemInserted event when an Insert button (a button with its CommandName property set to "Insert") within the control is clicked, but after the DetailsView control inserts the record. This allows you to provide an event handler that performs a custom routine, such as checking the results of an insert operation, whenever this event occurs.

A DetailsViewInsertedEventArgs object is passed to the event handler, which allows you to determine the number of records affected and any exceptions that might have occurred. To determine the number of records affected by the insert operation, use the AffectedRows property. Use the Exception property to determine whether any exceptions occurred. You can also indicate whether the exception was handled in the event handler by setting the ExceptionHandled property. If you need to access the values of the inserted record, use the Values property.

By default, the DetailsView control returns to the mode specified by the DefaultMode property after an insert operation. To keep the DetailsView control in insert mode, set the KeepInInsertMode property to true.

For more information about handling events, see NIB: Consuming Events.

For a list of initial property values for an instance of the DetailsViewDeletedEventArgs class, see the DetailsViewDeletedEventArgs constructor.

The following code example demonstrates how to use the DetailsViewInsertedEventArgs object passed to the event handler for the ItemInserted event to determine whether an exception occurred during an insert operation.

<%@ Page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

  void CustomerDetailsView_ItemInserted(Object sender, 
    DetailsViewInsertedEventArgs e)
    // Use the Exception property to determine whether an exception
    // occurred during the insert operation.
    if (e.Exception == null && e.AffectedRows == 1)
      // Use the Values property to get the value entered by 
      // the user for the CompanyName field.
      String name = e.Values["CompanyName"].ToString();

      // Display a confirmation message.
      MessageLabel.Text = name + " added successfully. ";

      // Insert the code to handle the exception.
      MessageLabel.Text = e.Exception.Message;

      // Use the ExceptionHandled property to indicate that the 
      // exception is already handled.
      e.ExceptionHandled = true;

      // When an exception occurs, keep the DetailsView
      // control in insert mode.
      e.KeepInInsertMode = true;


<html xmlns="" >
  <head runat="server">
    <title>DetailsViewInsertedEventArgs Example</title>
    <form id="form1" runat="server">

      <h3>DetailsViewInsertedEventArgs Example</h3>

        <asp:detailsview id="CustomerDetailsView"

          <fieldheaderstyle backcolor="Navy"


        <asp:label id="MessageLabel"

        <!-- This example uses Microsoft SQL Server and connects  -->
        <!-- to the Northwind sample database. Use an ASP.NET     -->
        <!-- expression to retrieve the connection string value   -->
        <!-- from the web.config file.                            -->
        <asp:sqldatasource id="DetailsViewSource"
          selectcommand="Select [CustomerID], [CompanyName], [Address], 
            [City], [PostalCode], [Country] From [Customers]"
          insertcommand="INSERT INTO [Customers]([CustomerID], 
            [CompanyName], [Address], [City], [PostalCode], 
            [Country]) VALUES (@CustomerID, @CompanyName, @Address, 
            @City, @PostalCode, @Country)"
            "<%$ ConnectionStrings:NorthWindConnectionString%>" 


.NET Framework
Available since 2.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
© 2015 Microsoft