DataList Control

The toolbox provides a DataList control for creating templated lists of data. A templated list is one in which you control the HTML used to render the list by defining templates: HTML that describes how to display one item in the list.

Tip

DataList controls provide simple templates; if you need precise control of the layout, consider using the Repeater control, covered below.

There are seven different templates available for defining the appearance of a DataList control, listed in Table 9-3. Of those templates, all but the ItemTemplate are optional.

Table 9-3. DataList templates

Template name

Description

AlternatingItemTemplate

Provides content and layout for every other item. If not defined, then the ItemTemplate will be used for every item in the DataList.

EditItemTemplate

Provides content and layout for the item currently being edited. If not defined, then the ItemTemplate will be used for the currently edited item.

FooterTemplate

Provides content and layout for the footer. If not defined, then the DataList will not have a footer.

HeaderTemplate

Provides content and layout for the header. If not defined, then the DataList will not have a header.

ItemTemplate

Required. Default definition for every item’s content and layout.

SelectedItemTemplate

Provides content and layout for the currently selected item. If not defined, then the ItemTemplate will be used.

SeparatorTemplate

Provides content and layout for the separator between items. If not defined, ...

Get Programming ASP.NET, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.