This documentation is archived and is not being maintained.

GridView.RowCommand Event

Occurs when a button is clicked in a GridView control.

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

event GridViewCommandEventHandler^ RowCommand {
	void add (GridViewCommandEventHandler^ value);
	void remove (GridViewCommandEventHandler^ value);
/** @event */
public void add_RowCommand (GridViewCommandEventHandler value)

/** @event */
public void remove_RowCommand (GridViewCommandEventHandler value)

In JScript, you can handle the events defined by a class, but you cannot define your own.
Not applicable.

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

Buttons within a GridView control can also invoke some of the built-in functionality of the control. To perform one of these operations, set the CommandName property of a button to one of the values in the following table.

CommandName value



Cancels an edit operation and returns the GridView control to read-only mode. Raises the RowCancelingEdit event.


Deletes the current record. Raises the RowDeleting and RowDeleted events.


Puts the current record in edit mode. Raises the RowEditing event.


Performs a paging operation. Sets the CommandArgument property of the button to "First", "Last", "Next", "Prev", or a page number to specify the type of paging operation to perform. Raises the PageIndexChanging and PageIndexChanged events.


Selects the current record. Raises the SelectedIndexChanging and SelectedIndexChanged events.


Sorts the GridView control. Raises the Sorting and Sorted events.


Updates the current record in the data source. Raises the RowUpdating and RowUpdated events.

Although the RowCommand event is raised when a button listed in the previous table is clicked, it is recommended that you use the events listed in the table for the operation.

A GridViewCommandEventArgs object is passed to the event-handling method, which allows you to determine the command name and command argument of the button clicked.


The GridViewCommandEventArgs class does not contain a property to indicate which row's button was clicked. If you need to know which row raised the event, pass the row's index to the event-handling method using the CommandArgument property.

For more information about handling events, see Consuming Events.

The following code example demonstrates how to use the RowCommand event to add the name of a customer from a GridView control to a ListBox control when a row's Add button is clicked.

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

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0