This documentation is archived and is not being maintained.

ListViewCommandEventArgs Class

Provides data for the ItemCommand event.


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

public class ListViewCommandEventArgs : CommandEventArgs

The ListViewCommandEventArgs type exposes the following members.

Public methodListViewCommandEventArgsInitializes a new instance of the ListViewCommandEventArgs class by using the specified source of the command and event arguments.

Public propertyCommandArgumentGets the argument for the command. (Inherited from CommandEventArgs.)
Public propertyCommandNameGets the name of the command. (Inherited from CommandEventArgs.)
Public propertyCommandSourceGets the source of the command.
Public propertyItemGets the data item for which the command was issued.

Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

The ItemCommand event is raised when a button in the ListView control is clicked. This enables you to provide an event-handling method that performs a custom routine whenever this event occurs.


The ListView control also raises other events when certain buttons are clicked (for example, buttons with the CommandName property set to "Delete", "Update", or "Page"). When you use one of these buttons, you can handle one of the specialized events that are provided by the control, such as the ItemDeleted or ItemDeleting events.

A ListViewCommandEventArgs object is passed to the event-handling method, which enables you to determine the command name and command argument of the button that was clicked. To determine the command name use the CommandName property, and to determine the command argument, use the CommandArgument property. You can also access the button control that raised the event by using the CommandSource property.

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

The following example shows how to use the ListViewCommandEventArgs object that is passed to the event handler.

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

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

<script runat="server">
  protected void EmployeesListView_OnItemCommand(object sender, ListViewCommandEventArgs e)
    if (String.Equals(e.CommandName, "AddToList"))
      // Verify that the employee ID is not already in the list. If not, add the
      // employee to the list.
      ListViewDataItem dataItem = (ListViewDataItem)e.Item;
      string employeeID = 

      if (SelectedEmployeesListBox.Items.FindByValue(employeeID) == null)
        ListItem item = new ListItem(e.CommandArgument.ToString(), employeeID);

<html xmlns="" >
<head id="Head1" runat="server">
    <title>Employee List</title>
    <form id="form1" runat="server">
      <asp:ListView runat="server" 
          <table runat="server" id="tblEmployees" 
                 cellspacing="0" cellpadding="1" width="440px" border="1">
            <tr id="itemPlaceholder" runat="server"></tr>
          <asp:DataPager ID="EmployeesDataPager" runat="server" PageSize="10">
              <asp:NumericPagerField />
          <tr runat="server">
              <asp:Label runat="server" ID="NameLabel" 
                Text='<%#Eval("LastName") + ", " + Eval("FirstName") %>' />
            <td style="width:80px">
              <asp:LinkButton runat="server" 
                Text="Add To List" 
                CommandArgument='<%#Eval("LastName") + ", " + Eval("FirstName") %>' />

      <br /><br />
      <b>Selected Employees:</b><br />
      <asp:ListBox runat="server" ID="SelectedEmployeesListBox" Rows="10" Width="300px" />

      <!-- 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="EmployeesDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT [EmployeeID], [FirstName], [LastName]
                       FROM HumanResources.vEmployee
                       ORDER BY [LastName], [FirstName], [EmployeeID]">

.NET Framework

Supported in: 4, 3.5

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

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