How to: Allow Users to Select Items in DataList Web Server Controls
You can specify that users can select individual items in the DataList Web server control. Typically, selecting an item highlights it visually. In addition, you might display different information for a selected item.
To allow users to select items in a DataList control
In the ItemTemplate (and AlternatingItemTemplate, if you are using it), add a Button or LinkButton Web server control.
Set the CommandName property of the button from Step 3 to select (case-sensitive).
Create an event handler for the DataList control's SelectedIndexChanged event. In the event handler, call the control's DataBind method to refresh the information in the control. The complete code would look something like this:
Protected Sub DataList1_SelectedIndexChanged(ByVal sender As _ System.Object, ByVal e As System.EventArgs) _ Handles DataList1.SelectedIndexChanged DataList1.DataBind() End Sub
To cancel the selection, set the control's SelectedIndex property to -1. To accomplish this, you could add a Button Web server control to the SelectedItem template and set its CommandName property to "unselect". The Click event for this button would also be forwarded to the DataGrid control's ItemCommand event.
The complete code might look something like the following: