RowCommand Event

GridView.RowCommand Event

Note: This event is new in the .NET Framework version 2.0.

Occurs when a button is clicked in a GridView control.

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

public:
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)

JScript supports the use of events, but not the declaration of new ones.

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

Description

"Cancel"

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

"Delete"

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

"Edit"

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

"Page"

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.

"Select"

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

"Sort"

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

"Update"

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.

NoteNote

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 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2016 Microsoft