asp.net.ph

Skip Navigation Links

DataList Control Syntax

ASP.NET Syntax   ASP.NET Syntax for Web Controls


Displays the items from a data source using templates. You can customize the appearance and contents of the control by manipulating the templates that make up the different components of the DataList control, such as the ItemTemplate and HeaderTemplate.

Declarative Syntax

For information on the individual members of this class, see DataList in the class library.

Remarks

You can manipulate the control’s layout and content by defining templates. The following table lists the different templates for the DataList control.

AlternatingItemTemplate Like the ItemTemplate element, but rendered for every other row in the DataList control. You can specify a different appearance for the AlternatingItemTemplate element by setting its style properties.
EditItemTemplate The layout of an item when it has been set into edit mode. This template typically contains editing controls ( such as TextBox controls ). The EditItemTemplate is invoked for a row in the DataList control when the EditItemIndex is set to the ordinal number of that row.
FooterTemplate The text and controls to render at the bottom of the DataList control.

The FooterTemplate cannot be data bound.

HeaderTemplate The text and controls to render at the top of the DataList control.

The HeaderTemplate cannot be data bound.

ItemTemplate The elements to render once for each row in the data source.
SelectedItemTemplate The elements to render when the user selects an item in the DataList control. Typical uses are to expand the number of data fields displayed and to visually mark the row with a highlight.
SeparatorTemplate The elements to render between each item.

The SeparatorTemplate item cannot be data bound.

You can customize the appearance of the DataList control by specifying a style for the different parts of the control. The following table lists the style properties that control the appearance of the different parts of the DataList control.

Style property Description Style class
AlternatingItemStyle The style for every other item. TableItemStyle
EditItemStyle The style for the item being edited. TableItemStyle
FooterStyle The style for the footer at the end of the list ( if any ). TableItemStyle
HeaderStyle The style for the header at the beginning of the list ( if any ). TableItemStyle
ItemStyle The style for individual items. TableItemStyle
SelectedItemStyle The style for the selected item. TableItemStyle
SeparatorStyle The style for the separator between each item. TableItemStyle

NOTE: The DataList control differs from the Repeater control by supporting directional rendering ( by use of the RepeatColumns and RepeatDirection properties ) and the option to render within an HTML table.

The Items collection contains the data-bound members of the DataList control. The collection is populated when the DataBind method is called on the DataList control. The header item ( if any ) is added first, then one Item object for each data row. If a SeparatorTemplate exists, separators are created and added between each item, but these are not added to the Items collection.

After all items have been created for the rows in the DataSource, the footer item is added to the control ( but not to the Items collection ). Finally, the control raises the ItemCreated event for each item, including the header, footer, and separators. Unlike most collections, the Items collection does not expose, add, or remove any methods. However, you can modify the contents within an item by providing a handler for the ItemCreated event.

See Also

DataList Class   DataList Web Server Control



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note