O'Reilly logo

Programming ASP.NET 3.5, 4th Edition by Jesse Liberty, Dan Hurwitz, Dan Maharry

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

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

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