GridView.RowCommand Event
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)
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 | 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.
Note: |
|---|
| 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.
Note: