Name

DataList

Synopsis

The DataList control is a databound list that is configured through templates in the .aspx file. It does not provide quite the extent of features found in the DataGrid control. It does provide support for automatic selection (by setting the SelectedIndex property) and editing (by setting the EditItemIndex property), but not for automatic paging or sorting. Also, there is no support for default column types or automatically generated rows, so you will always need to specify at least an ItemTemplate. Templates for the DataList are bracketed inside the appropriate template tag (like <ItemTemplate>) and may contain a data binding expression (for example, <%# Container.DataItem("Description") %>). You can also add HTML tags or tags for ASP.NET controls to these templates manually for a customized appearance.

You can use the AlternatingItemTemplate property to allow items to alternate between two styles, the EditItemTemplate to specify how items will appear when they are being edited, and the SelectedItemTemplate to specify how items will appear when they are selected. The HeaderTemplate, FooterTemplate, and SeparatorTemplate allow you specify layout and content for special rows. The DataList has a number of properties that allow you to control its appearance. You can set TableItemStyle objects for various properties, including footers, headers (used automatically for column titles), and items. (The corresponding DataList properties end with the word “Style.”) You ...

Get ASP.NET in a Nutshell 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.