The Repeater control is used to display a repeated list of items that are bound to the control. The Repeater control may be bound to a database table, an XML file, or another list of items.
Example
Template Name | Description |
---|---|
ItemTemplate | Defines the content and layout of items within the list. Required. |
AlternatingItemTemplate | If defined, the AlternatingItemTemplate determines the content and layout of alternating items. If not defined, ItemTemplate is used. |
SeparatorTemplate | If defined, the SeparatorTemplate is rendered between items (and alternating items). If not defined, a separator is not rendered. |
HeaderTemplate | If defined, the HeaderTemplate determines the content and layout of the list header. If not defined, header is not rendered. |
FooterTemplate | If defined, the FooterTemplate determines the content and layout of the list footer. If not defined, footer is not rendered. |
Example
<asp:Repeater id=Repeater1 runat="server"> <HeaderTemplate> <table border=1> <tr> <td><b>Company</b></td> <td><b>Code</b></td> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td> <%# Eval("Name") %> </td> <td> <%# Eval("Code") %> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> <p> <b>Repeater2:</b> <p> <asp:Repeater id=Repeater2 runat="server"> <HeaderTemplate> Company data: </HeaderTemplate> <ItemTemplate> <%# Eval("Name") %><%#Eval("Code") %>)</ItemTemplate> <SeparatorTemplate>, </SeparatorTemplate> </asp:Repeater>
In .cs page
void Page_Load(Object Sender, EventArgs e) { if (!IsPostBack) { ArrayList values = new ArrayList(); values.Add("Microsoft", "2001"); values.Add("Intel", "2002"); values.Add("Dell", "2003"); Repeater1.DataSource = values; Repeater1.DataBind(); } }
Output
Company Symbol
Microsoft 2001
Intel 2002
Dell 2003