System.Web.UI.WebControls Namespace DataList Class
Occurs when a cancel command button associated with an item in the DataList control is clicked.
[ VB ]
Public Event CancelCommand As DataListCommandEventHandler
[ C# ]
public event DataListCommandEventHandler CancelCommand;
[ C++ ]
public: __event DataListCommandEventHandler* CancelCommand;
In [ JScript ], you can handle the events defined by a class, but you cannot define your own.
The CancelCommand event is raised whenever a Cancel button associated with an item in the DataList control is clicked. The event is typically used to trigger a handler that cancels any edits made to an item in the DataList control.
Controls such as cancel 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 cancel command can be activated at any time for any item in the list. You do not have to assign the same handler for each cancel button.
Information related to the CancelCommand 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 CancelCommand event, to cancel any edits made to an item in a DataList control.
The below snippet shows how to attach a handler for the event.
<asp:datalist id = "myDataList" runat = "server"
onCancelCommand = "myListCancelHandler" ... >
The below shows how the handler method is defined, which simply resets the EditItemIndex to -1, essentially setting edit mode off. The list is then re-bound to the source to refresh the display back to the layout defined in the ItemTemplate.
void myListCancelHandler ( Object src, DataListCommandEventArgs e ) {
myList.EditItemIndex = -1;
PopulateList ( );
}
Show me
DataList Members DeleteCommand EditCommand UpdateCommand Allowing Users to Edit Items in a DataList Control