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