System.Web.UI.WebControls Namespace DataList Class
Specifies the template to use for the selected item in a DataList.
<asp:datalist ... >
<selecteditemtemplate>
... template definition here
</selecteditemtemplate>
</asp:datalist>
An ITemplate interface that defines how the selected item in the DataList control is rendered.
The property is read/write with no default value.
The SelectedItemTemplate functions in the same way as the ItemTemplate, but rendered only for the selected row in the DataList control. You can set the appearance for the item in this template using the SelectedItemStyle property.
To specify a template for the selected item in a DataList, declare a <SelectedItemTemplate> element between the opening and closing tags of the control. You can then list the contents of the template between the opening and closing <SelectedItemTemplate> ... </SelectedItemTemplate>
tags.
The item in the SelectedItemTemplate is data-bound. To display data in the SelectedItemTemplate, declare one or more Web server controls and set their data-binding expressions to evaluate to a field in the DataList control's DataSource.
First Name: <asp:Label runat = "server"
Text = "<%# Eval ( "FirstName" ) %>" />
For more information, see DataBinding Expression Syntax.
The following example illustrates using the SelectedItemTemplate to display the selected item of a DataList in a different layout and format.
<asp:datalist id = "myDataList" runat = "server"
selecteditemstyle-backcolor = "khaki"
...
onItemCommand = "showItem">
<itemtemplate>
... template definition for individual items here
</itemtemplate>
<selecteditemtemplate>
<b><%# Eval ( "FirstName" ) %>
<%# Eval ( "LastName" ) %></b><br>
<%# Eval ( "Title" ) %><br>
<%# Eval ( "Address" ) %>,
<%# Eval ( "City" ) %>
</selecteditemtemplate>
</asp:datalist>
Show me
DataList Members SelectedIndex SelectedIndexChanged SelectedItem SelectedItemStyle Allowing Users to Select Items in a DataList Control