asp.net.ph

DataList.SelectedItemTemplate Property

System.Web.UI.WebControls Namespace   DataList Class


Specifies the template to use for the selected item in a DataList.

Syntax

<asp:datalist ... >

   <selecteditemtemplate>
      ... template definition here
   </selecteditemtemplate>

</asp:datalist>

Property Value

An ITemplate interface that defines how the selected item in the DataList control is rendered.

The property is read/write with no default value.

Remarks

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.

Example

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 

See Also

DataList Members   SelectedIndex   SelectedIndexChanged   SelectedItem   SelectedItemStyle   Allowing Users to Select 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