ASP. NET Web Forms-DataList control, formsdatalist

Source: Internet
Author: User

ASP. NET Web Forms-DataList control, formsdatalist

ASP. NET Web Forms-DataList control.

The DataList control, similar to the Repeater control, is used to display the duplicate list of projects bound to the control. However, the DataList control adds tables to the Data project by default.

Bind DataSet to DataList Control

The DataList control, similar to the Repeater control, is used to display the duplicate list of projects bound to the control. However, the DataList control adds tables to the Data project by default. The DataList 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 DataList 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

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:

Gridlines = "both" runat = "server">

My CD Catalog

"<% # Container. DataItem (" title ") %>"

<% # Container. DataItem ("artist") %>-

$ <% # Container. DataItem ("price") %>

Copyright Hege Refsnes

Use Style

You can also add a style to the DataList control to make the output more fancy:

Instance

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

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">

My CD Catalog

"<% # Container. DataItem (" title ") %>"

<% # Container. DataItem ("artist") %>-

$ <% # Container. DataItem ("price") %>

Copyright Hege Refsnes

Use

You can add an element after the element to describe the appearance of the alternate line in the output. You can add a style to the area data in the DataList control:

Instance

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

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">

My CD Catalog

"<% # Container. DataItem (" title ") %>"

<% # Container. DataItem ("artist") %>-

$ <% # Container. DataItem ("price") %>

"<% # Container. DataItem (" title ") %>"

<% # Container. DataItem ("artist") %>-

$ <% # Container. DataItem ("price") %>

©Hege Refsnes

Related Article

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.