asp.net.ph

DataList.UpdateCommand Event

System.Web.UI.WebControls Namespace   DataList Class


Occurs when an update command button associated with an item in the DataList control is clicked.

[ VB ]
Public Event UpdateCommand As DataListCommandEventHandler

[ C# ]
public event DataListCommandEventHandler UpdateCommand;

[ C++ ]
public: __event DataListCommandEventHandler* UpdateCommand;

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

Remarks

The UpdateCommand event is raised whenever an Update button associated with an item in the DataList control is clicked. The event is typically used to trigger a handler that updates any edits made to an item in the DataList control.

Controls such as update 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 update command can be activated at any time for any item in the list. You do not have to assign the same handler for each update button.

Event Data

Information related to the UpdateCommand 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.

Example

The following code snippets illustrate how to specify and code a handler for the UpdateCommand event, to update the data source with 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" 
   onUpdateCommand = "myListUpdateHandler" ... >

The below shows how the handler method is defined, which basically ( updates the corresponding row in the data source, then ) resets the EditItemIndex property 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 myListUpdateHandler ( Object src, DataListCommandEventArgs e ) {
   // ... code to update data source here ... 
   myList.EditItemIndex = -1;
   PopulateList ( );
}

 Show me 

See Also

DataList Members   CancelCommand   DeleteCommand   EditCommand   Allowing Users to Edit Items in a DataList 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