asp.net.ph

GridViewCommandEventArgs Class

System.Web.UI.WebControls Namespace


.NET Framework version 2.0

Provides data for the command events of a GridView.

GridViewCommandEventArgs Class Members

Collapse   Constructors

Visibility Constructor Parameters
public GridViewCommandEventArgs ( GridViewRow row , Object commandSource , CommandEventArgs originalArgs )
public GridViewCommandEventArgs ( Object commandSource , CommandEventArgs originalArgs )

Collapse   Properties

Visibility Name Value Type Accessibility
public CommandSource Object [ Get ]
public Handled Boolean [ Get , Set ]

Remarks

The GridViewCommandEventArgs provides event data for the following command events of a GridView.

The generic 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 custom command buttons for the GridView control.

NOTE: The GridView control also raises other specialized events when certain buttons ( such as a cancel, delete, edit, or update button ) associated with a row in the GridView is clicked. When using these buttons, you should consider handling one of the specialized events provided by the control ( RowCancelingEdit, RowDeleting, RowEditing, or RowUpdating ).

For more information about handling events, see Web Forms Events Model.

Example

The following example demonstrates using GridViewCommandEventArgs properties to obtain information about the currently selected item in a GridView control.

void updateCart ( Object src, GridViewCommandEventArgs e ) {
   DataRow dr = Cart.NewRow ( );

   // get the row index stored in the CommandArgument property
   int index = Convert.ToInt32 ( e.CommandArgument );

   // get the GridViewRow where the command is raised
   GridViewRow selectedRow = ( ( GridView ) e.CommandSource ).Rows [ index ];

   // for bound fields, values are stored in the Text property of Cells [ fieldIndex ]
   string item = selectedRow.Cells [ 1 ].Text;
   string price = selectedRow.Cells [ 2 ].Text;

   if ( e.CommandName == "AddToCart" ) {
      dr [ 0 ] = item; dr [ 1 ] = price;
      Cart.Rows.Add ( dr );
   }
   else {  // remove from Cart
      CartView.RowFilter = "Item='" + item + "'";
      if ( CartView.Count > 0 ) CartView.Delete ( 0 );
      CartView.RowFilter = "";
   }
   shopCart.DataBind ( );
}
Run Sample | View Source
See Also

GridView   GridViewCommandEventHandler   RowCommand 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