The DataList control, such as the Repeater control, used to display duplicates of the project manifest is an inevitable control. However, the DataList control adds a preset value for a table's data item.
A dataset bound to DataList control
The DataList control, such as the Repeater control, used to display duplicates of the project manifest is an inevitable control. However, the DataList control adds a preset value for a table's data item. DataList controls can be bound to a database table, an XML file, or another list of items. Here, we will show how to combine XML files into DataList control.
We will use the following XML file in our example ("Cdcatalog.xml"):
<?xml version= "1.0" encoding= "Iso-8859-1"?>
<catalog> <cd> <title>empire burlesque</title> <artist>bob dylan</artist> < country>usa</country> <company>Columbia</company> <price>10.90</price> <year >1985</year> </cd> <cd> <title>hide your heart</title> <artist>bonnie Tyler </artist> <country>UK</country> <company>cbs records</company> <price>9.90< /price> <year>1988</year> </cd> <cd> <title>greatest hits</title> <artist >dolly parton</artist> <country>USA</country> <company>RCA</company> <price >9.90</price> <year>1982</year> </cd> <cd> <title>still got the blues</ title> <artist>gary moore</artist> <country>UK</country> <company>virgin Records </company> <price>10.20</price> <year>1990</year> </cd> ≪cd> <title>Eros</title> <artist>eros ramazzotti</artist> <country>eu</ country> <company>BMG</company> <price>9.90</price> <year>1997</year> </ Cd> </catalog>
Look at the XML file: Cdcatalog.xml
First, the import of the "System.Data" namespace. We need this kind of naming and DataSet object. Include one of the following directives. ASPX pages:
"% @ Import named =" System.Data "%"
Next, you create an XML file for the dataset and load the XML file into the DataSet page first:
<script runat= "Server" >
sub Page_Load
if not Page.IsPostBack then
Dim mycdcatalog=new DataSet
Mycdcatalog. READXML (MapPath ("Cdcatalog.xml")) End-
If End
Sub
Then, we create a DataList. ASPX pages. The content of the
te> content is to provide the first and only output, and then the content of the <ItemTemplate> repeat element for each "record" in the data,
Last year, content < footertemplate> element once supplied output:
<form runat= "Server" > <asp:d Atalist id= "Cdcatalog" runat= "Server"
<HeaderTemplate> ...
& Lt;itemtemplate> </itemtemplate>
<FooterTemplate> ... </footertemplate>
</asp:datalist> </form>
</body>
Then we added the script to create the dataset and constrain the DataList control in the Mycdcatalog dataset. We also fill in the DataList control with <HeaderTemplate> included in the title table, a <ItemTemplate>, which contains data showing items, and <FooterTemplate>, which contains text. Note that the Grid line property DataList is set to two to display the bounds of the table: