ASP. NET Web Forms-Repeater control, formsrepeater
ASP. NET Web Forms-Repeater control.
The Repeater control is used to display the duplicate list of projects bound to the control.
Bind DataSet to Repeater control
The Repeater control is used to display the duplicate list of projects bound to the control. The Repeater control can be bound to database tables, XML files, or other project lists. Here, we will demonstrate how to bind an XML file to the Repeater control.
In our instance, we will use the following XML file ("cdcatalog. xml "):
Bob Dylan
USA
Columbia
10.90
1985
Bonnie Taylor
UK
CBS Records
9.90
1988
Dolly Parton
USA
RCA
9.90
1982
Gary Moore
UK
Virgin records
10.20
1990
Eros Ramazzotti
EU
BMG
9.90
1997
View the XML file: cdcatalog. xml
First, import the "System. Data" namespace. We need the namespace to work with the DataSet object. Include the following command 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 DataSet when the page is loaded for the first time:
TitleArtistCountryCompanyPriceYear
<% # Container. dataItem ("title") %> <% # Container. dataItem ("artist") %> <% # Container. dataItem ("country") %> <% # Container. dataItem ("company") %> <% # Container. dataItem ("price") %> <% # Container. dataItem ("year") %>
Use
You can add an element after the element to describe the appearance of the alternate line in the output. In the following example, the table is displayed with a light gray background every row:
Instance
<% @ Import Namespace = "System. Data" %>
TitleArtistCountryCompanyPriceYear
<% # 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") %>
Use
An element is used to describe the delimiter between each record. In the following example, a horizontal line is inserted between each table row:
Instance
<% @ Import Namespace = "System. Data" %>
TitleArtistCountryCompanyPriceYear
<% # Container. dataItem ("title") %> <% # Container. dataItem ("artist") %> <% # Container. dataItem ("country") %> <% # Container. dataItem ("company") %> <% # Container. dataItem ("price") %> <% # Container. dataItem ("year") %>