Introduction
In this article, I’ll present a tutorial with an example: a way to use the DataList control in ASP.NET for displaying information/records from the database using SQL DataSource.
So, first, we will discuss ASP.NET data list control.
What is a data list control in ASP.NET?
The DataList control, just like the Repeater control, maybe a model-driven, lightweight control that acts as an instrumentality of continual information. The templates during this control area unit define the information that it'll contain. It is versatile in the sense that you simply will easily customize the display of 1 or many records that area unit displayed within the management. You've got a property within the DataList management known as RepeatDirection that may be used to customize the layout of the control.
For creating a database, you can follow this SQL query as per your requirements. In this article, I am creating one temp table with some duplicate records to demonstrate the data list control.
Create Table
Insert Data into Table
Get Data From Table
Drop Table
- Table: this is often the default layout. The Table layout renders the DataList as an associate hypertext markup language (HTML) Table and it renders within the Table Cell. The number of Cells in every row will be set using the Repeat Columns property.
- Flow: The Flow layout doesn't render the DataList as any markup language component. All the DataList things are rendered directly even as for how the Repeater control repeats its things.
- OrderedList and UnorderedList: The OrderedList and UnorderedList layouts render the DataList as markup language Ordered List and Unordered List. But in .Net 4.0 and higher than these aren't supported any longer.
- DataList management and Templates: The DataList control makes use of the subsequent templates.
- HeaderTemplate: The content of this example won't be recurrent and can be placed in the topmost position, i.e., the head section of the DataList control.
- ItemTemplate: The contents of this example are recurrent for every record present in its DataSource.
- AlternatingItemTemplate: AlternatingItemTemplate is used for adding alternate things. It's used together with ItemTemplate, usually for displaying a unique style for alternating things.
- SeparatorTemplate: This example is used to feature an extractor between 2 things of the DataList control.
- FooterTemplate: The content of this example won't be continual and can be placed at the bottom-most position i.e. footer section of the DataList control.
HTML Markup
The following markup language consists of associate ASP.NET DataList control and ASP.NET SqlDataSource control.
The SqlDataSource control is about with the subsequent properties.
ConnectionString
Name of the Connection String setting within the web.Config file.
Selectcommand
The Select statement is to fetch the records from the Employee table of the Northwind database.
The ID of the SqlDataSource control is about the DataSourceID of the DataList control.
Output Screen
![Output Screen]()