Chapter 3. Using List Controls

In This Chapter

Working with CheckBoxList controls

Toiling with ListItem elements

Utilizing RadioButtonList controls

Employing ListBox controls

Making use of DropDownList controls

Doing more with ListItem elements

The controls I present in Chapter 1 of this mini-book work with individual items of data. In this chapter, you get a look at four server controls that work with lists of data. First are the CheckBoxList and RadioButtonList controls, which display lists of check boxes and radio buttons. Finally, the ListBox control and DropDownList controls are presented. These controls let the user select an item from a list of options.

Using the CheckBoxList Control

The CheckBoxList control displays a list of check boxes. It provides a simple way to present a set of options to the user without requiring you to code each check box individually.

Figure 3-1 shows a page that displays a CheckBoxList control. Here, the CheckBoxList control lists several toppings that can be ordered on a pizza. When the user clicks the Order Pizza button, the program displays the items selected by the user in a label that appears beneath the button.

A page with a Check BoxList control.

Figure 3-1. A page with a Check BoxList control.

Here’s the C# markup used to create the CheckBoxList control shown in Figure 3-1:

<asp:CheckBoxList ID="cblToppings" runat="server"> <asp:ListItem>Pepperoni</asp:ListItem> <asp:ListItem>Linguica</asp:ListItem> ...

Get ASP.NET 2.0 All-In-One Desk Reference For Dummies® 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.