Programmingempire
As I have said in my previous post on DataList control, it is a template-based data-bound control. For the purpose of understanding the basics of DataList Control, read this article. Today I will explain the Properties and Methods of DataList Control in ASP.NET.
Properties and Methods of DataList Control
Since the DataList control is a container control for data items, it contains properties for the layout of data items, their appearance, how to display different sections of the list, key fields for data manipulation, and so on. Accordingly, some of the important properties of the DataList control are given below.
Contents and Layout
As discussed earlier, the DataList control makes use of templates for displaying data items in different sections of the list. Accordingly, it has ItemTemplate and AlternatingItemTemplate for displaying the data items. Similarly, the HeaderTemplate and the FooterTemplate show the header and footer sections respectively. Furthermore, EditItemTemplate and SelectedItemTemplate show the item currently being edited or selected respectively. Finally, the SeparatorTemplate shows the separator between data items.
Customization of Appearance
For the purpose of customization of appearance, the DataList control offers the Style property associated with each type of template. Accordingly, it has ItemStyle, AlternatingItemStyle, HeaderStyle, FooterStyle, EditItemStyle, SelectedItemStyle, and SeparatorStyle properties.
Direction of Display of DataList Items
The following properties control direction of the display, and the number of columns in the DataList control.
- RepeatColumn
- RepeatDirection
- RepeatLayout
Therefore, the number of columns in the DataList is determined by the RepeatColumn property. Whereas, whether the data items are displayed row-wise or column-wise, is determined by the RepeatDirection property. Accordingly, the Horizontal value for RepeatDirection indicates the display of data items row-wise, whereas the Vertical value for RepeatDirection indicates the display of data items column-wise. Moreover, the RepeatLayout property specifies whether the layout is Table or Flow.
Display Header and Footer Sections
Since the header and footer sections of the DataList control are not visible by default, it has two properties for it – ShowHeader, and ShowFooter. As can be seen, both of these properties are boolean and make the header and footer section visible respectively when set to true.
Data Keys
Since, the DataList control allows edit, and delete functions of data items, it also has properties for managing data keys. For instance, for specifying the data key, we can use the DataKeyField property. Also, the DataKeys refers to the collection of keys for each record. Moreover, if you want to retrieve the keys as an object of ArrayList, you can use the DataKeysArray property. Furthermore, the DataList also has a property known as EditItemIndex that returns the index of the item currently being edited.
Apart from properties, the DataList control also has several fields, methods, and events. Read more on DataList members here.
Summary
In this article on Properties and Methods of DataList Control in ASP.NET, the important properties of this control are discussed. While, the fields, methods, and events will be discussed in the next article.
Further Reading
Parameter and ParameterCollection in ADO.NET
Database Manipulation Using DataGrid
Example of Button and Link Button Control in ASP.NET
Example of Chart Control in ASP.NET
Creating a DataTable from a DataReader in ASP.NET
Deleting a Record using DataGrid Control in ASP.NET
Edit a Record Using DataGrid Control in ASP.NET
Insert a Record Using ItemCommand Event in DataGrid
CRUD Operations with DataGrid in ASP.NET
Creating Columns in a DataGrid Control
XML Documents and DataSet in ASP.NET
ASP.NET Core Features and Advantages
Display Images Using DataList Control
Adding Images Using Image Control
Creating a Group of Radio Buttons Using RadioButtonList Control
Example of Button Control in ASP.NET
ItemDataBound Event in DataList
More Features of DataList in ASP.NET
A Simple Example of Using a DataList Control in ASP.NET
Properties and Methods of DataList Control in ASP.NET
Exploring DataList Control in ASP.NET
Custom Validator Control in ASP.NET
Validation Summary Control in ASP.NET
Validation Controls Examples – RequiredFieldValidator, CompareValidator, and RangeValidator
An Example of Data Binding with RadioButtonList Control
Binding Data to Web Control in ADO.NET
Examples of AdRotator Control in ASP.NET