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
<asp:DataList
AccessKey = "string"
BackColor = "color name | #dddddd"
BorderColor = "color name | #dddddd"
BorderStyle = "NotSet | None | Dotted | Dashed | Solid | Double | Groove |
Ridge | Inset | Outset"
BorderWidth = size
Caption = "string"
CaptionAlign = "NotSet | Top | Bottom | Left | Right"
CellPadding = integer
CellSpacing = integer
CssClass = "string"
DataKeyField = "string"
DataMember = "string"
DataSource = "string"
DataSourceID = "string"
EditItemIndex = integer
Enabled = "True | False"
EnableTheming = "True | False"
EnableViewState = "True | False"
ExtractTemplateRows = "True | False"
Font-Bold = "True | False"
Font-Italic = "True | False"
Font-Names = "string"
Font-Overline = "True | False"
Font-Size = "string | Smaller | Larger | XX-Small | X-Small | Small |
Medium | Large | X-Large | XX-Large"
Font-Strikeout = "True | False"
Font-Underline = "True | False"
ForeColor = "color name | #dddddd"
GridLines = "None | Horizontal | Vertical | Both"
Height = size
HorizontalAlign = "NotSet | Left | Center | Right | Justify"
ID = "string"
OnCancelCommand = "CancelCommand event handler"
OnDataBinding = "DataBinding event handler"
OnDeleteCommand = "DeleteCommand event handler"
OnDisposed = "Disposed event handler"
OnEditCommand = "EditCommand event handler"
OnInit = "Init event handler"
OnItemCommand = "ItemCommand event handler"
OnItemCreated = "ItemCreated event handler"
OnItemDataBound = "ItemDataBound event handler"
OnLoad = "Load event handler"
OnPreRender = "PreRender event handler"
OnSelectedIndexChanged = "SelectedIndexChanged event handler"
OnUnload = "Unload event handler"
OnUpdateCommand = "UpdateCommand event handler"
RepeatColumns = integer
RepeatDirection = "Horizontal | Vertical"
RepeatLayout = "Table | Flow"
runat = "server"
SelectedIndex = integer
ShowFooter = "True | False"
ShowHeader = "True | False"
SkinID = "string"
Style = "string"
TabIndex = integer
ToolTip = "string"
UseAccessibleHeader = "True | False"
Visible = "True | False"
Width = size
>
<AlternatingItemStyle />
<AlternatingItemTemplate>
<!-- child controls -->
</AlternatingItemTemplate>
<EditItemStyle />
<EditItemTemplate>
<!-- child controls -->
</EditItemTemplate>
<FooterStyle />
<FooterTemplate>
<!-- child controls -->
</FooterTemplate>
<HeaderStyle />
<HeaderTemplate>
<!-- child controls -->
</HeaderTemplate>
<ItemStyle />
<ItemTemplate>
<!-- child controls -->
</ItemTemplate>
<SelectedItemStyle />
<SelectedItemTemplate>
<!-- child controls -->
</SelectedItemTemplate>
<SeparatorStyle />
<SeparatorTemplate>
<!-- child controls -->
</SeparatorTemplate>
</asp:DataList>
For information on the individual members of this class, see DataList in the class library.
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.
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.
DataList Class DataList Web Server Control