This documentation is archived and is not being maintained.

ListViewDeletedEventArgs.Keys Property

Gets the key or keys for the deleted item.

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

public IOrderedDictionary Keys { get; }

Property Value

Type: System.Collections.Specialized.IOrderedDictionary
The key or keys for the deleted item.

Use the Keys property to access the values of the key fields (as specified by the ListView.DataKeyNames property) for a deleted item. For example, you can use these values to keep a log of deleted items.


This property contains only the key fields. To access the non-key fields, use the Values property.

The Keys property returns an object that implements the IOrderedDictionary interface. The object contains DictionaryEntry objects that represent the key fields of the deleted item.

The following example shows how to use the Keys property to access the values of the key fields for a deleted item.

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

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

<script runat="server">

  void ContactsListView_ItemDeleted(Object sender, ListViewDeletedEventArgs e)
    // Display the value of the key fields in the Keys property.
    KeysMessageLabel.Text =
      "The key fields for the deleted record are: <br/>";

    foreach (DictionaryEntry entry in e.Keys)
      DisplayValue(entry, KeysMessageLabel);

    // Display the value of the non-key fields in the Values  
    // property.
    ValuesMessageLabel.Text =
      "The non-key fields for the deleted record are: <br/>";

    foreach (DictionaryEntry entry in e.Values)
      DisplayValue(entry, ValuesMessageLabel);


  void DisplayValue(DictionaryEntry entry, Label displayLabel)
    // Display the field name contained in the DictionaryEntry object. 
    if (entry.Key != null)
      displayLabel.Text += "Name=" + entry.Key.ToString() + ", ";
      displayLabel.Text += "Name=null, ";

    // Display the field value contained in the DictionaryEntry object. 
    if (entry.Value != null)
      displayLabel.Text += "Value=" + entry.Value.ToString() + "<br/>";
      displayLabel.Text += "Value=null<br/>";


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

      <h3>ListViewDeletedEventArgs Keys and Values Example</h3>

      <asp:Label ID="Message"


      <asp:ListView ID="ContactsListView" 
          <table cellpadding="2" runat="server" id="tblContacts" width="640px">
            <tr id="itemPlaceholder" runat="server"></tr>
          <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='<%#Bind("FirstName") %>' />
              <asp:Label ID="LastNameLabel" runat="server" Text='<%#Bind("LastName") %>' />
              <asp:Label ID="EmailLabel" runat="server" Text='<%#Bind("EmailAddress") %>' />
              <asp:LinkButton ID="DeleteButton" runat="server" 
                OnClientClick="return confirm('Are you sure?');" />

      <br/><br />

      <asp:Label ID="KeysMessageLabel"


      <asp:Label ID="ValuesMessageLabel"

      <!-- 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" />


Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5