This documentation is archived and is not being maintained.

ListView::ItemCommand Event

Occurs when a button in a ListView control is clicked.

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

 event EventHandler<ListViewCommandEventArgs^>^ ItemCommand {
	void add (EventHandler<ListViewCommandEventArgs^>^ value);
	void remove (EventHandler<ListViewCommandEventArgs^>^ value);
<asp:ListView OnItemCommand="EventHandler" />

The ItemCommand event is raised when a button in the ListView control is clicked. This enables you to perform a custom routine whenever this event occurs.

Buttons in a ListView control can also invoke built-in functionality of the control. The following table lists values that you can use with the CommandName property of a button in order to invoke built-in functionality.

CommandName value



Cancels an edit or insert operation. Raises the ItemCanceling event.


Deletes the current record from the data source. Raises the ItemDeleted and ItemDeleting events.


Sets the SelectedIndex property to the DisplayIndex property value for the item. Renders the SelectedItemTemplate template for the item. Raises the SelectedIndexChanging and SelectedIndexChanged events.


Puts the item in edit mode. Renders the EditItemTemplate template for the item. Raises the ItemEditing event.


Inserts the bound values from the InsertItemTemplate template into the data source. Raises the ItemInserting and ItemInserted events.


Updates the current record in the data source with the bound values from the EditItemTemplate template. Raises the ItemUpdating and ItemUpdated events.


Sorts the columns listed in the CommandArgument property of the button. Raises the Sorting and Sorted events.

The ItemCommand event is also raised when a button that is listed in the previous table is clicked. However, it is recommended that you use the events listed in the table. The ItemCommand event is usually used to handle custom operations.

A ListViewCommandEventArgs object is passed to the event handler, which enables you to determine the command name and command argument of the button that was clicked. To determine the command name, use the CommandEventArgs::CommandName property. To determine the command argument, use the CommandEventArgs::CommandArgument property. To access the control that raised the event, use the ListViewCommandEventArgs::CommandSource property.

For more information about how to handle events, see Consuming Events.

The following example shows how to create an ItemCommand event handler.

No code example is currently available or this language may not be supported.

.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.