O'Reilly logo

ASP.NET in a Nutshell by Matthew MacDonald, G. Andrew Duthie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required