asp.net Getting Started Tutorial: asp.net DataList control

Source: Internet
Author: User

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> &Lt;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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.