See Also: DataList Members
In this topic:
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.
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.
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. |
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.
The DataList control can contain controls that enable users to enter information.
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.
Example
<asp:DataList AccessKey="string" BackColor="color name|#dddddd" BorderColor="color name|#dddddd" BorderStyle="