ListViewDeletedEventArgs Class
Collapse the table of content
Expand the table of content

ListViewDeletedEventArgs Class


Provides data for the ItemDeleted event.

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


public class ListViewDeletedEventArgs : EventArgs

System_CAPS_pubmethodListViewDeletedEventArgs(Int32, Exception)

Initializes a new instance of the ListViewDeletedEventArgs class.


Gets the number of rows that were affected by the delete operation.


Gets the exception, if any, that was raised during the delete operation.


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


Gets the key or keys for the deleted item.


Gets the non-key field values for the deleted item.


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 ListView control raises the ItemDeleted event when a Delete button in the control is clicked or the DeleteItem method is called, but after the ListView control deletes the item. (A Delete button is a button whose CommandName property is set to "Delete".) This enables you to provide an event-handling method that performs a custom routine whenever this event occurs, such as checking the results of a delete operation.

A ListViewDeletedEventArgs object is passed to the event-handling method. This object enables you to determine the number of items affected and any exceptions that might have occurred. To determine the number of items that were affected by the delete operation, use the AffectedRows property. To determine whether any exceptions occurred, use the Exception property. You can indicate whether you have handled the exception in the event-handling method by setting the ExceptionHandled property.


If an exception occurs during the delete operation and the ExceptionHandled property is set to false, the ListView control re-throws the exception.

To access the key fields of the deleted item, use the Keys property. To access non-key fields of the deleted item, use the Values property. For a list of initial property values for an instance of the ListViewDeletedEventArgs class, see the ListViewDeletedEventArgs constructor.

The following example shows how to use the ListViewDeletedEventArgs object to determine whether an exception occurred during a delete operation. The ListViewDeletedEventArgs object is passed to the event-handling method for the ItemDeleted event.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<script runat="server">

    void Page_Load()
        Message.Text = String.Empty;

    void ContactsListView_ItemDeleted(Object sender, ListViewDeletedEventArgs e)
        // Determine whether an exception occurred during the delete operation.
        if (e.Exception == null)
            // Ensure that a record was deleted.
            if (e.AffectedRows > 0)
                Message.Text = e.AffectedRows + " item(s) deleted successfully.";
                Message.Text = "No item was deleted.";
            // Insert the code to handle the exception here.

            // Indicate that the exception has been handled.
            e.ExceptionHandled = true;
            Message.Text = "An error occurred during the delete operation.";


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

      <h3>ListViewDeletedEventArgs Example</h3>

      <asp:Label ID="Message"

      <asp:ListView ID="ContactsListView" 
          <table cellpadding="2" runat="server" id="tblContacts" width="640px">
            <tr runat="server" id="itemPlaceholder" />
          <asp:DataPager runat="server" ID="PeopleDataPager" PageSize="12">
                ShowFirstPageButton="true" ShowLastPageButton="true"
                FirstPageText="|&lt;&lt; " LastPageText=" &gt;&gt;|"
                NextPageText=" &gt; " PreviousPageText=" &lt; " />
          <tr runat="server">
            <td valign="top">
              <asp:Label ID="FirstNameLabel" runat="server" Text='<%#Eval("FirstName") %>' />
              <asp:Label ID="LastNameLabel" runat="server" Text='<%#Eval("LastName") %>' />
              <asp:Label ID="EmailLabel" runat="server" Text='<%#Eval("EmailAddress") %>' />
              <asp:LinkButton ID="DeleteButton" runat="server" 
                OnClientClick="return confirm('Are you sure?');" />

      <!-- This example uses Microsoft SQL Server and connects    -->
      <!-- to the AdventureWorks sample database. Use an ASP.NET  -->
      <!-- expression to retrieve the connection string value     -->
      <!-- from the Web.config file.                              -->            
      <asp:SqlDataSource ID="ContactsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT [ContactID], [FirstName], [LastName], [EmailAddress] 
          FROM Person.Contact"
        DeleteCommand="DELETE FROM Person.Contact WHERE [ContactID] = @ContactID">
            <asp:Parameter Name="ContactID" Type="Int32" />


.NET Framework
Available since 3.5

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