The DataList Control

The toolbox provides a DataList control for creating templated lists of data. A templated list is one in which you control the HTML used to render the list by defining templates: each template describes how to display one item in the list.

Tip

DataList controls provide fairly simple templates; if you need very precise control of the layout, consider using the Repeater control.

To get started create a new web site called webNorthWindDataControls and copy the web site named WebNorthWind. Add a web form to your application named DataControls. Right-click on DataControls.aspx in the Solution explorer, and make it the start page for your application.

Switch to Design view and drag a DataList control onto Datacontrols.aspx. Notice that the smart tag opens, offering you an opportunity to choose a data source. Choose New Data Source and for this exercise, choose SQL Database, naming the new data source DataListCustomerDataSources. Use your existing connection to Northwind, and specify that you want all the fields in the Customers table. When you finish, the DataList is populated with labels that represent the field names, and labels that are bound to the data control, as shown in Figure 11-27.

DataList bound to SQL data control

Figure 11-27. DataList bound to SQL data control

If you click on Source, you will see that the DataList has been defined with a number of attributes to identify its data source, as ...

Get Programming Visual Basic 2005 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.