Javatpoint Logo
Javatpoint Logo

ASP.NET DataList

The ASP.NET DataList control is a light weight server side control that works as a container for data items. It is used to display data into a list format to the web pages.

It displays data from the data source. The data source can be either a DataTable or a table from database.

Here, first, we are creating DataList that gets data from a DataTable. This example includes the following files.

ASP.NET DataList Example with DataTable

// DataListExample2.aspx


// DataListExample2.aspx.cs


It produces the following output to the browser.

ASP Net Datalist 1

ASP.NET DataList Example with database

This example gets data from the database table and includes the following steps.

1) Add a Web Form

Add a web form to drag the DataList over it as we did in the following screen shot.

ASP Net Datalist 2

Select DataList from the data category of the toolbox.

ASP Net Datalist 3

Drag the DataList to the form. After dragging, it looks like the following.

ASP Net Datalist 4

Now, we need to configure database connection. Click on it and set new data source.

ASP Net Datalist 5

It will pop up a new window with various Data Sources. Select SQL database and click ok.

ASP Net Datalist 6

After selecting Data Source, now, we need to select data connection. But before proceeding further add connection string to the web.config file.

// web.config

Data Source is the name of the connection that is required to connect SQL Server. It can be different for other computer systems.

ASP Net Datalist 7

After clicking next, it asks to configure select statement.

ASP Net Datalist 8

It allows us to select number of columns to fetch custom record. It also provides * option to select all columns records.

Now, test the configured query, is it working or not, as we did in the below screenshot.

ASP Net Datalist 9

After finishing configuration, our DataList looks like this:

ASP Net Datalist 10

This "DataListExample.aspx" file contains the following code.


This application produces the following output.

ASP Net Datalist 11
Next TopicASP.NET DataGrid

Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA