asp.net.ph

GridView.RowCommand Event

System.Web.UI.WebControls Namespace   GridView Class


.NET Framework version 2.0

Occurs when a button within a GridView control is clicked.

[ VB ]
Public Event RowCommand As GridViewCommandEventHandler

[ C# ]
public event GridViewCommandEventHandler RowCommand;

[ C++ ]
public: __event GridViewCommandEventHandler* RowCommand;

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

Remarks

The RowCommand event is raised whenever any button associated with a row in the GridView is clicked. This provides for programmatically determining which specific command button is clicked and take appropriate action.

This event is commonly used to handle button controls with a given CommandName value in the GridView control.

Event Data

Information related to the RowCommand event is passed via a GridViewCommandEventArgs object to the method assigned to handle the event. The following GridViewCommandEventArgs properties provide information specific to this event.

Property Description
CommandArgument Gets the argument for the command ( Inherited from CommandEventArgs ).
CommandName Gets the name of the command ( Inherited from CommandEventArgs ).
CommandSource Gets the source of the command — the button that raised the event.

Example

The following example illustrates a way to handle the RowCommand event of a GridView control.

Whenever any of the LinkButton controls within the GridView is clicked, data from the selected row is obtained using the three GridViewCommandEventArgs properties described above.

This information is then processed and added to or removed from another GridView control.

The below snippet shows how to attach a handler for the event.

<asp:gridview id = "myGridView" runat = "server"
   onRowCommand = "updateCart" ... >

The below shows how the handler method is defined.

Run Sample | View Source
See Also

GridView Members   GridViewCommandEventArgs Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph