Lists of Data

Let’s start with the most straightforward controls to which to bind data—read-only selection lists. As you saw in Chapter 4, there are several different server controls we can use to create a list of items to choose from based on data you provide to them:

  • CheckBoxList

  • DropDownList

  • RadioButtonlist

  • BulletedList

  • ReorderList

Indeed, you already saw how to bind data from an array to these lists in Chapter 4. Binding data from a DataSource control is just as straightforward.

Tip

All the properties highlighted in this section on lists are available for all five list controls, not just for the DropDownList control used in the following examples.

Binding Data to a List

Open VS2008 and create a new website for this chapter, called C8_DataAccess. Delete Default.aspx and add a new web form to the site, called SelectionList.aspx. In Design view, drag a SqlDataSource onto the page and rename it dsCustomers. Choose Configure Data Source from its smart tag and, as you did in Chapter 7, use the wizard to set the DataSource so that it connects to the AdventureWorksLT database. However, when asked how to retrieve the data from the database, choose “Specify a custom SQL statement or stored procedure” and click Next.

Selection lists need only two values from a database—one to display and one to use as the value corresponding to the display—so use the following statement and click Next. You’ll use the full name of the customer to display in the list, and the CustomerID will be the value to carry forward. ...

Get Programming ASP.NET 3.5, 4th Edition 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.