System.Web.UI.WebControls.DataList Class

A data bound list control that displays items using templates.

See Also: DataList Members

Syntax

[System.ComponentModel.Editor("System.Web.UI.Design.WebControls.DataListComponentEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.ComponentEditor, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
[System.Web.UI.ControlValueProperty("SelectedValue")]
[System.ComponentModel.Designer("System.Web.UI.Design.WebControls.DataListDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.IDesigner")]
public class DataList : BaseDataList, System.Web.UI.INamingContainer, IRepeatInfoUser

Remarks

In this topic:

Introduction

Use the System.Web.UI.WebControls.DataList control to display a template-defined data bound list. The System.Web.UI.WebControls.DataList control supports selecting and editing.

Templates

The contents of the System.Web.UI.WebControls.DataList control can be manipulated by using templates. The following table lists the supported templates.

DataList.AlternatingItemTemplate

If defined, provides the content and layout for alternating items in the System.Web.UI.WebControls.DataList. If not defined, ItemTemplate is used.

DataList.EditItemTemplate

If defined, provides the content and layout for the item currently being edited in the System.Web.UI.WebControls.DataList. If not defined, ItemTemplate is used.

DataList.FooterTemplate

If defined, provides the content and layout for the footer section of the System.Web.UI.WebControls.DataList. If not defined, a footer section will not be displayed.

DataList.HeaderTemplate

If defined, provides the content and layout for the header section of the System.Web.UI.WebControls.DataList. If not defined, a header section will not be displayed.

DataList.ItemTemplate

Required template that provides the content and layout for items in the System.Web.UI.WebControls.DataList.

DataList.SelectedItemTemplate

If defined, provides the content and layout for the currently selected item in the System.Web.UI.WebControls.DataList. If not defined, DataList.ItemTemplate is used.

DataList.SeparatorTemplate

If defined, provides the content and layout for the separator between items in the System.Web.UI.WebControls.DataList. If not defined, a separator will not be displayed.

At the very minimum, the DataList.ItemTemplate needs to be defined to display the items in the System.Web.UI.WebControls.DataList control. Additional templates can be used to provide a custom look to the System.Web.UI.WebControls.DataList control.

Customizing the Appearance of the DataList Control

The appearance of the System.Web.UI.WebControls.DataList control may be customized by setting the style properties for the different parts of the control. The following table lists the different style properties.

DataList.AlternatingItemStyle

Specifies the style for alternating items in the System.Web.UI.WebControls.DataList control.

DataList.EditItemStyle

Specifies the style for the item being edited in the System.Web.UI.WebControls.DataList control.

DataList.FooterStyle

Specifies the style for the footer in the System.Web.UI.WebControls.DataList control.

DataList.HeaderStyle

Specifies the style for the header in the System.Web.UI.WebControls.DataList control.

DataList.ItemStyle

Specifies the style for the items in the System.Web.UI.WebControls.DataList control.

DataList.SelectedItemStyle

Specifies the style for the selected item in the System.Web.UI.WebControls.DataList control.

DataList.SeparatorStyle

Specifies the style for the separator between the items in the System.Web.UI.WebControls.DataList control.

You can also show or hide different parts of the control. The following table lists the properties that control which parts are shown or hidden.

DataList.ShowFooter

Shows or hides the footer section of the System.Web.UI.WebControls.DataList control.

DataList.ShowHeader

Shows or hides the header section of the System.Web.UI.WebControls.DataList control.

Display Direction and Layout

The display direction of a System.Web.UI.WebControls.DataList control can be vertical or horizontal. Set the DataList.RepeatDirection property to specify the display direction.

The layout of the System.Web.UI.WebControls.DataList control is controlled with the DataList.RepeatLayout property. Setting this property to RepeatLayout.Table will display the System.Web.UI.WebControls.DataList in a table format, while RepeatLayout.Flow displays the System.Web.UI.WebControls.DataList without a table structure.

Security

The DataList control can contain controls that enable users to enter information.

Note:

This control can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. You can use validation controls to verify user input before displaying the input text in a control. ASP.NET provides an input request validation feature to block script and HTML in user input.

For more information about security, see Securing Standard Controls, How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings, and Validating User Input in ASP.NET Web Pages.

Declarative Syntax

Example

<asp:DataList
    AccessKey="string"
    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    BorderStyle="

Requirements

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0