asp.net.ph

DataGrid.EditCommand Event

System.Web.UI.WebControls Namespace   DataGrid Class


Occurs when an edit command button associated with an item in the DataGrid control is clicked.

[ VB ]
Public Event EditCommand As DataGridCommandEventHandler

[ C# ]
public event DataGridCommandEventHandler EditCommand;

[ C++ ]
public: __event DataGridCommandEventHandler* EditCommand;

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

Remarks

The EditCommand event is raised whenever an Edit button associated with an item in the DataGrid control is clicked. The event is typically used to trigger a handler that sets the selected item in the DataGrid to edit mode.

Controls such as edit command buttons that are defined within the items of a parent container such as the DataGrid bubbles their event up the control hierarchy to the containing DataGrid control. This provides a convenient way to assign one handler for the same command event at the DataGrid level, as only one edit command can be activated at any time for any item in the grid. You do not have to assign the same handler for each edit button.

Event Data

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

Property Description
CommandArgument ( inherited from CommandEventArgs ) Gets the argument for the command.
CommandName ( inherited from CommandEventArgs ) Gets the name of the command.
CommandSource Gets the source of the command.
Item Gets the selected item in the DataGrid.

Example

The following code snippets illustrate how to specify and code a handler for the EditCommand event, to determine the item to edit in a DataGrid control.

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

<asp:datagrid id = "myGrid" runat = "server" 
   onEditCommand = "myGridEditHandler" ... >

The below shows how the handler method is defined, which simply sets the EditItemIndex to the index of the selected item, essentially setting the item in edit mode. The grid is then re-bound to the source to refresh the display, with the selected item rendered with text boxes as the default editing controls for each column bound to the data source.

void myGridEditHandler ( Object src, DataGridCommandEventArgs e ) {
   myGrid.EditItemIndex = e.Item.ItemIndex;
   PopulateList ( );
}

 Show me 

See Also

DataGrid Members   CancelCommand   DeleteCommand   UpdateCommand   Allowing Users to Edit Items in a DataGrid Control 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