Como: Permitir usuários selecionarem itens em controles DataList do servidor Web
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.
Para permitir que usuários selecionem itens em um controle DataList
Create a SelectedItemTemplate to define the layout of markup and controls for a selected item.Para obter detalhes, consulte:Modelos de controles servidores web ASP.NET.
Set the control's SelectedItemStyle properties.Para obter detalhes, consulte:Controle de Servidor Web do ASP.NET e Estilos CSS.
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).
Crie um manipulador de eventos para o evento SelectedIndexChanged do controle DataList.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
protected void DataList1_SelectedIndexChanged (object sender, System.EventArgs e) { DataList1.DataBind(); }
Para cancelar a seleção conjunto SelectedIndex propriedade como -1. Para fazer isso, você pode adicionar um Button Web de controle de servidor para o SelectedItem modelo e defina seu CommandNamepropriedade para "Cancelar". The Click event for this button would also be forwarded to the DataGrid control's ItemCommand event.
O código completo poderia ser algo assim:
Protected Sub DataList1_ItemCommand(ByVal source As Object, _
ByVal e As DataListCommandEventArgs) _
Handles DataList1.ItemCommand
If e.CommandName = "unselect" Then
DataList1.SelectedIndex = -1
End If
DataList1.DataBind()
End Sub