System.Web.UI.WebControls Namespace DataList Class
Occurs when a button within a DataList control is clicked.
[ VB ]
Public Event ItemCommand As DataListCommandEventHandler
[ C# ]
public event DataListCommandEventHandler ItemCommand;
[ C++ ]
public: __event DataListCommandEventHandler* ItemCommand;
In [ JScript ], you can handle the events defined by a class, but you cannot define your own.
The ItemCommand event is raised whenever any button associated with an item in the DataList is clicked. This provides for programmatically determining which specific command button is clicked and take appropriate action. This event is commonly used to handle button controls with a given CommandName value in the DataList control.
Information related to the ItemCommand 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.
The following example illustrates a way to handle the ItemCommand event of a DataList. Information about the selected item is displayed whenever any of the LinkButton controls within the DataList is clicked.
The below snippet shows how to attach a handler for the event.
<asp:datalist id = "myDataList" runat = "server" onItemCommand = "showItem" ... >
The below shows how the handler method is defined.
void showItem ( Object src, DataListCommandEventArgs e ) {
myDataList.SelectedIndex = e.Item.ItemIndex;
string query = "SELECT * FROM Employees";
myDataList.DataSource = fetchData ( query, "northwind" );
myDataList.DataBind ( );
}
Show me
DataList Members