| |||||||||||
DataGrid.CancelCommand EventSystem.Web.UI.WebControls Namespace DataGrid Class Occurs when a cancel command button associated with an item in the DataGrid control is clicked. [ VB ] Public Event CancelCommand As DataGridCommandEventHandler [ C# ] public event DataGridCommandEventHandler CancelCommand; [ C++ ] public: __event DataGridCommandEventHandler* CancelCommand; In [ JScript ], you can handle the events defined by a class, but you cannot define your own. RemarksThe CancelCommand event is raised whenever a Cancel button associated with an item in the DataGrid control is clicked. The event is typically used to trigger a handler that cancels any edits made to an item in the DataGrid control. Controls such as cancel 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 cancel command can be activated at any time for any item in the grid. You do not have to assign the same handler for each cancel button. Event DataInformation related to the CancelCommand 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.
ExampleThe 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 DataGrid control. The below snippet shows how to attach a handler for the event. <asp:datagrid id = "myDataGrid" runat = "server" onCancelCommand = "myGridCancelHandler" ... > The below shows how the handler method is defined, which simply resets the EditItemIndex to -1, essentially setting edit mode off. The grid is then re-bound to the source to refresh the display back to the default grid layout. void myGridCancelHandler ( Object src, DataGridCommandEventArgs e ) {
myGrid.EditItemIndex = -1;
PopulateList ( );
}
See AlsoDataGrid Members DeleteCommand EditCommand UpdateCommand Allowing Users to Edit Items in a DataGrid Control |
| ||||||||||
Check out related books at Amazon
© 2000-2008 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 aspxtreme