System.Web.UI.WebControls Namespace DataList Class
Specifies the template to use for each item in a DataList.
<asp:datalist ... >
<itemtemplate>
... template definition here
</itemtemplate>
</asp:datalist>
An ITemplate interface that defines how the individual items in the DataList control are rendered.
The property is read/write with no default value.
The ItemTemplate describes the layout of elements that are rendered once for each row in the data source. You can set the appearance for the items in this template using the ItemStyle property.
To specify a template for the items of a DataList, declare an <ItemTemplate> element between the opening and closing tags of the control. You can then list the contents of the template between the opening and closing <ItemTemplate> ... </ItemTemplate>
tags.
Items in the ItemTemplate are data-bound. To display data in the ItemTemplate, 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 ItemTemplate to define the layout and content of each item in a DataList.
<asp:datalist id = "myList" repeatcolumns=2 runat = "server">
<itemtemplate>
<table cellpadding=10>
<tr>
<td valign = "top">
<a href='details_title.aspx?titleid=<%# DataBinder.Eval (
Container.DataItem, "title_id" ) %>'>
<img align = "top" alt = "Click for details" border=0
src='<%# Eval ( "title_id",
"/shared/images/title-{0}.gif" ) %>'>
</a>
</td>
<td valign = "top">
<b>Title:</b> <%# Eval ( "title" ) %><br>
<b>Category:</b> <%# Eval ( "type" ) %><br>
<b>Pub ID:</b> <%# Eval ( "pub_id" ) %><br>
<b>Price:</b> <%# Eval ( "price", "{0:c}" ) %>
</td></tr>
</table>
</itemtemplate>
</asp:datalist>
Show me
DataList Members AlternatingItemTemplate EditItemTemplate SelectedItemTemplate HeaderTemplate FooterTemplate SeparatorTemplate