ASP. NET-datalist Control

Source: Internet
Author: User

In this example, we will use the following XML file ("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 Taylor </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>

The datalist control, similar to the Repeater control, is used to display duplicate lists of projects restricted to this control. However, the datalist control adds tables to the Data project by default.


 
<% @ Import namespace = "system. Data" %>

<script  runat="server">
sub Page_Load
if Not Page.IsPostBack then
   dim mycdcatalog=New DataSet
   mycdcatalog.ReadXml(MapPath("cdcatalog.xml"))
   cdcatalog.DataSource=mycdcatalog
   cdcatalog.DataBind()
end if
end sub
</script>

<HTML>
<Body>

<Form runat = "server">
<Asp: datalist
Id = "cdcatalog"
Gridlines = "both"
Runat = "server">

<Headertemplate>
My CD catalog
</Headertemplate>

<Itemtemplate>
"<%#Container.DataItem("title")%>"
<%#Container.DataItem("artist")%>-$<%#Container.DataItem("price")%>
</Itemtemplate>

<Footertemplate>
Copy right w3school.com.cn
</Footertemplate>

</ASP: datalist>
</Form>

</Body>
</Html>

 Datalist control with styles

<% @ Import namespace = "system. Data" %>

<script  runat="server">
sub Page_Load
if Not Page.IsPostBack then
   dim mycdcatalog=New DataSet
   mycdcatalog.ReadXml(MapPath("cdcatalog.xml"))
   cdcatalog.DataSource=mycdcatalog
   cdcatalog.DataBind()
end if
end sub
</script>

<HTML>
<Body>

<Form runat = "server">
<Asp: datalist id = "cdcatalog"
Runat = "server"
Cellpadding = "2"
Cellspacing = "2"
Borderstyle = "Inset"
Backcolor = "# e8e8e8"
Width = "100%"
Headerstyle-font-name = "verdana"
Headerstyle-font-size = "12pt"
Headerstyle-horizontalalign = "center"
Headerstyle-font-bold = "true"
Itemstyle-backcolor = "#778899"
Itemstyle-forecolor = "# ffffff"
Footerstyle-font-size = "9pt"
Footerstyle-font-italic = "true">

<Headertemplate>
My CD catalog
</Headertemplate>

<Itemtemplate>
"<%#Container.DataItem("title")%>"
<%#Container.DataItem("artist")%>-$<%#Container.DataItem("price")%>
</Itemtemplate>

<Footertemplate>
Copy right w3school.com.cn
</Footertemplate>

</ASP: datalist>
</Form>

</Body>
</Html>


Datalist control with <alternatingitemtemplate>

<% @ Import namespace = "system. Data" %>

<script  runat="server">
sub Page_Load
if Not Page.IsPostBack then
   dim mycdcatalog=New DataSet
   mycdcatalog.ReadXml(MapPath("cdcatalog.xml"))
   cdcatalog.DataSource=mycdcatalog
   cdcatalog.DataBind()
end if
end sub
</script>

<HTML>
<Body>

<Form runat = "server">
<Asp: datalist id = "cdcatalog"
Runat = "server"
Cellpadding = "2"
Cellspacing = "2"
Borderstyle = "Inset"
Backcolor = "# e8e8e8"
Width = "100%"
Headerstyle-font-name = "verdana"
Headerstyle-font-size = "12pt"
Headerstyle-horizontalalign = "center"
Headerstyle-font-bold = "true"
Itemstyle-backcolor = "#778899"
Itemstyle-forecolor = "# ffffff"
Alternatingitemstyle-backcolor = "# e8e8e8"
Alternatingitemstyle-forecolor = "#000000"
Footerstyle-font-size = "9pt"
Footerstyle-font-italic = "true">

<Headertemplate>
My CD catalog
</Headertemplate>

<Itemtemplate>
"<%#Container.DataItem("title")%>"
<%#Container.DataItem("artist")%>
-$<%#Container.DataItem("price")%>
</Itemtemplate>

<Alternatingitemtemplate>
"<%#Container.DataItem("title")%>"
<%#Container.DataItem("artist")%>-$<%#Container.DataItem("price")%>
</Alternatingitemtemplate>

<Footertemplate>
Copy right w3school.com.cn
</Footertemplate>

</ASP: datalist>
</Form>

</Body>
</Html>
 

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.