ASP.NET Web Forms - DataList Control
The DataList control, similar to the Repeater control, is used to display a repeated list of items bound to the control. However, the DataList control adds a table to the data items by default.
Binding a DataSet to the DataList Control
The DataList control, similar to the Repeater control, is used to display a repeated list of items bound to the control. However, the DataList control adds a table to the data items by default. The DataList control can be bound to a database table, an XML file, or other item lists. Here, we will demonstrate how to bind an XML file to the DataList control.
In our example, we will use the following XML file ("cdcatalog.xml"):
View this XML file:cdcatalog.xml
First, import the "System.Data" namespace. We need this namespace to work with the DataSet object. Include the following directive 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 the DataSet when the page is first loaded:
Demo Example »
Using Styles
You can also add styles to the DataList control to make the output fancier:
Example
<%@ Import Namespace="System.Data" %>
Demo Example »
Use
You can add
Example
<%@ Import Namespace="System.Data" %>
Demo Example »