asp.net.ph

Repeater.ItemTemplate Property

System.Web.UI.WebControls Namespace   Repeater Class


Specifies the template to use for each item in a Repeater.

Syntax

<asp:repeater ... >

   <itemtemplate>
      ... template definition here
   </itemtemplate>

</asp:repeater>

Property Value

An ITemplate interface that defines how the individual items in the Repeater control are rendered.

The property is read/write with no default value.

Remarks

The ItemTemplate describes the layout of elements that are rendered once for each row in the data source.

To specify a template for the items of a Repeater, place 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 Repeater control's DataSource.

First Name: <asp:Label runat = "server"
   Text = "<%# Eval ( "FirstName" ) %>" />

For more information, see DataBinding Expression Syntax.

The Repeater allows to split HTML tags across its templates. For example, to render content bound to a single-field data source into a bulleted or ordered list, include

To render content bound to a multiple-field data source into a table using templates, include


Example

The following example illustrates using the ItemTemplate to display the items of a Repeater into an HTML table element.

<asp:repeater id = "myRepeater" runat = "server">

   <headertemplate>
      <table width=90% cellpadding=5>
      <tr style = "background-color:#ddc">
         <th>Product</th>
         <th>Price</th></tr>
   </headertemplate>

   <itemtemplate>
      <tr>
         <td><%# Eval ( "ProductID" ) %></td>
         <td align = "right"><%# Eval ( 
            "UnitPrice", "{0:c}" ) %></td></tr>
   </itemtemplate>

   <footertemplate>
      </table>
   </footertemplate>

</asp:repeater>

 Show me 

See Also

Repeater Members   AlternatingItemTemplate   HeaderTemplate   FooterTemplate   SeparatorTemplate 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