Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ASP.NET Repeater Control

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 a database table, an XML file, or other item lists. 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"):

Empire Burlesque

Bob Dylan

USA

Columbia

10.90

1985

Hide your heart

Bonnie Tyler

UK

CBS Records

9.90

1988

Greatest Hits

Dolly Parton

USA

RCA

9.90

1982

Still got the blues

Gary Moore

UK

Virgin records

10.20

1990

Eros

Eros Ramazzotti

EU

BMG

9.90

1997

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:

<%@ Import Namespace="System.Data" %>

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

Title Artist Country Company Price Year
<%#Container.DataItem("title")%> <%#Container.DataItem("artist")%> <%#Container.DataItem("country")%> <%#Container.DataItem("company")%> <%#Container.DataItem("price")%> <%#Container.DataItem("year")%>

Demo Example »


Use

You can add the element after the element, used to describe the appearance of alternating rows in the output. In the example below, every other row of the table is displayed with a light gray background:

Example

<%@ Import Namespace="System.Data" %>

Title Artist Country Company Price Year
<%#Container.DataItem("title")%> <%#Container.DataItem("artist")%> <%#Container.DataItem("country")%> <%#Container.DataItem("company")%> <%#Container.DataItem("price")%> <%#Container.DataItem("year")%>
<%#Container.DataItem("title")%> <%#Container.DataItem("artist")%> <%#Container.DataItem("country")%> <%#Container.DataItem("company")%> <%#Container.DataItem("price")%> <%#Container.DataItem("year")%>

Demo Example »


Use

element is used to describe the separator between each record. In the example below, a horizontal line is inserted between each table row:

Example

<%@ Import Namespace="System.Data" %>

Title Artist Country Company Price Year
<%#Container.DataItem("title")%> <%#Container.DataItem("artist")%> <%#Container.DataItem("country")%> <%#Container.DataItem("company")%> <%#Container.DataItem("price")%> <%#Container.DataItem("year")%>

Demo Example »