Easy Tutorial
❮ Prop Webcontrol Table Cellpadding Met Websecurity Createuserandaccount ❯

ASP.NET Web Forms - Repeater Control


The Repeater control is used to display a repeated list of items bound to the control.


Binding a DataSet to the Repeater Control

The Repeater control is used to display a repeated list of items bound to the control. The Repeater control can be bound to database tables, XML files, or other list items. Here, we will demonstrate how to bind an XML file to the Repeater control.

In our example, we will use the following XML file ("cdcatalog.xml"):

View this XML file: cdcatalog.xml

First, import the "System.Data" namespace. We need this namespace to work with the DataSet object. Include the following directive at the top of the .aspx page:

Next, create a DataSet for the XML file and load the XML file into the DataSet when the page is first loaded:

Then, create a Repeater control in the .aspx page. The content in the <HeaderTemplate> element is rendered first and appears only once in the output, while the content in the <ItemTemplate> element is repeated for each "record" in the DataSet. Finally, the content in the <FooterTemplate> element appears only once in the output:

Then, add the script to create the DataSet and bind the mycdcatalog DataSet to the Repeater control. Use HTML tags to populate the Repeater control and bind data items to cells within the <ItemTemplate> area using <%#Container.DataItem("fieldname")%>:

Example


Using <AlternatingItemTemplate>

You can add an <AlternatingItemTemplate> element after the <ItemTemplate> element to describe the appearance of alternating rows in the output. In the following example, the table alternates with a light gray background every other row:

Example


Using <SeparatorTemplate>

The <SeparatorTemplate> element is used to describe the separator between each record. In the following example, a horizontal line is inserted between each table row:

Example

❮ Prop Webcontrol Table Cellpadding Met Websecurity Createuserandaccount ❯