System.Web.UI.WebControls Namespace DataList Class
Occurs when an edit command button associated with an item in the DataList control is clicked.
[ VB ]
Public Event EditCommand As DataListCommandEventHandler
[ C# ]
public event DataListCommandEventHandler EditCommand;
[ C++ ]
public: __event DataListCommandEventHandler* EditCommand;
In [ JScript ], you can handle the events defined by a class, but you cannot define your own.
The EditCommand event is raised whenever an Edit button associated with an item in the DataList control is clicked. The event is typically used to trigger a handler that sets the selected item in the DataList to edit mode.
Controls such as edit command buttons that are defined in the item template of a parent container such as the DataList bubbles their event up the control hierarchy to the containing DataList control. This provides a convenient way to assign one handler for the same command event at the DataList level, as only one edit command can be activated at any time for any item in the list. You do not have to assign the same handler for each edit button.
Information related to the EditCommand event is passed via a DataListCommandEventArgs object to the method assigned to handle the event. The following DataListCommandEventArgs 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 DataList. |
The following code snippets illustrate how to specify and code a handler for the EditCommand event, to determine the item to edit in a DataList control.
The below snippet shows how to attach a handler for the event.
<asp:datalist id = "myDataList" runat = "server"
onEditCommand = "myListEditHandler" ... >
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 list is then re-bound to the source to refresh the display, with the selected item using the layout defined in the EditItemTemplate.
void myListEditHandler ( Object src, DataListCommandEventArgs e ) {
myList.EditItemIndex = e.Item.ItemIndex;
PopulateList ( );
}
Show me
DataList Members CancelCommand DeleteCommand UpdateCommand Allowing Users to Edit Items in a DataList Control