DataList Class
Assembly: System.Web (in system.web.dll)
[ControlValuePropertyAttribute(L"SelectedValue")] public ref class DataList : public BaseDataList, INamingContainer, IRepeatInfoUser
/** @attribute ControlValuePropertyAttribute("SelectedValue") */
public class DataList extends BaseDataList implements INamingContainer, IRepeatInfoUser
ControlValuePropertyAttribute("SelectedValue") public class DataList extends BaseDataList implements INamingContainer, IRepeatInfoUser
Not applicable.
Use the DataList control to display a template-defined data bound list. The DataList control supports selecting and editing.
The contents of the DataList control can be manipulated by using templates. The following table lists the supported templates.
| Template Name | Description |
|---|---|
| If defined, provides the content and layout for alternating items in the DataList. If not defined, ItemTemplate is used. | |
| If defined, provides the content and layout for the item currently being edited in the DataList. If not defined, ItemTemplate is used. | |
| If defined, provides the content and layout for the footer section of the DataList. If not defined, a footer section will not be displayed. | |
| If defined, provides the content and layout for the header section of the DataList. If not defined, a header section will not be displayed. | |
| Required template that provides the content and layout for items in the DataList. | |
| If defined, provides the content and layout for the currently selected item in the DataList. If not defined, ItemTemplate is used. | |
| If defined, provides the content and layout for the separator between items in the DataList. If not defined, a separator will not be displayed. |
At the very minimum, the ItemTemplate needs to be defined to display the items in the DataList control. Additional templates can be used to provide a custom look to the DataList control.
The appearance of the 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.
| Style Property | Description |
|---|---|
| Specifies the style for alternating items in the DataList control. | |
| Specifies the style for the item being edited in the DataList control. | |
| Specifies the style for the footer in the DataList control. | |
| Specifies the style for the header in the DataList control. | |
| Specifies the style for the items in the DataList control. | |
| Specifies the style for the selected item in the DataList control. | |
| Specifies the style for the separator between the items in the 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.
| Property | Description |
|---|---|
| Shows or hides the footer section of the DataList control. | |
| Shows or hides the header section of the DataList control. |
The display direction of a DataList control can be vertical or horizontal. Set the RepeatDirection property to specify the display direction.
The layout of the DataList control is controlled with the RepeatLayout property. Setting this property to RepeatLayout.Table will display the DataList in a table format, while RepeatLayout.Flow displays the DataList without a table structure.
Caution: |
|---|
| 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 Introduction to Validating User Input in ASP.NET Web Pages.
The following code example demonstrates how to use a DataList control to display a list of items from a data source.
Note: |
|---|
| The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model. |
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
System.Web.UI.Control
System.Web.UI.WebControls.WebControl
System.Web.UI.WebControls.BaseDataList
System.Web.UI.WebControls.DataList
Reference
DataList MembersSystem.Web.UI.WebControls Namespace
BaseDataList
DataGrid
Repeater
Other Resources
DataList Web Server Control OverviewSecuring Standard Controls
How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings
Introduction to Validating User Input in ASP.NET Web Pages
ASP.NET Web Page Code Model
DataList Web Server Control
Caution:
Note: