To begin with, in this post on Exploring DataList Control in ASP.NET, I will explain the DataList control. In short, it is one of the feature-rich, lightweight data-bound control available in ASP.NET. In general, we use the DataList control to display the multiple rows of data.
Although, ASP.NET offers several data-bound controls the DataList control provides a much greater degree of customization and appearance control. The following list shows the important features of the DataList control.
Important Points Regarding the DataList Control
- Basically, it is a template-based control.
- Therefore, it contains several different types of templates that we can utilize to display and manipulate data items.
- In order to control the appearance of displayed data, the DataList control has corresponding style properties for each template.
- Since it acts as the container of data, the dataList control may use either data from a DataTable object or data from a physical database.
Templates Used in the DataList Control
As can be seen below, the DataList control can have the following seven types of templates.
- In general, the ItemTemplate is responsible for displaying the content of the data source in the list. Also, it is the mandatory template that you should always include in the DataList control.
- Another template that displays the data items is known as the AlternatingItemTemplate. Basically, it displays the alternate rows of data when you include this template in the DataList control. Otherwise, the alternate rows of data items also displayed using the ItemTemplate only.
- Since you want to use different types of controls when an item is being edited, you can do this using the EditItemTemplate. Basically, this template provides the controls for editing the current item.
- Whenever you want to display the currently selected item in a particular way, you can use the SelectedItemTemplate that specifies the content and layout of the current selection.
- In order to display the header section in a specific format, you can use the HeaderTemplate.
- Likewise, you can also display the footer section using the FooterTemplate.
- Finally, a SeparatorTemplate specifies a separator between the items of the DataList.
The following figure shows an example of displaying data using the DataList control.
In this article on Exploring DataList Control in ASP.NET, you have learned the basic concepts of the DataListControl. Also, the different types of templates available with control are also discussed here. In the next article, you will learn the properties, methods, and events contained in the DataList.