ListBox

The ListBox control allows users to select one or more items from a predefined list. It differs from a DropDownList control in that it can display multiple items at once and it optionally allows the user to select multiple items.

To add a ListBox control to a page

  1. Drag the ListBox control from the Toolbox panel to your page.

  2. Set properties for the control in the Tag Properties panel.

Common ListBox Properties

Property Description

SelectionMode

Set to Single or Multiple to specify how many items users can select.

Rows

Specifies the number of rows displayed. You can set the control to display a specific number of items. If the control contains more items than that, it displays a vertical scroll bar.

Height and Width

Specifies the size of the control using pixels. When you specify a Height and Width, the control ignores the number of rows you have set and displays as many as will fit into the height of the control. Some browsers do not support setting the Height and Width in pixels and will use the row count setting.

For a full description of all ListBox control properties, see ListBox Properties Cc295286.xtlink_newWindow(en-us,Expression.40).png in the MSDN library.

Adding items to the ListBox control

Before a ListBox can present a user with items to choose, you need to populate the ListBox control with the items. You can do this by binding the control to a data source or by individually defining items for the ListBox.

To bind the ListBox control to a data source

  1. In Design view, right-click the ListBox control, and then click Show CommonControl Tasks****.

  2. On the Common DropDownList Tasks menu, click Choose Data Source.

  3. In the Data Source Configuration Wizard, choose a source for the ListBox control in the Select a data source dropdown. In the Select a data field to display in theListBox**** dropdown, select the field for the text that the user will see. In the Selecta data field for the value of the ListBox**** dropdown, select the field for the data that can be programmatically accessed when the user chooses an item in the list.

To define items for the ListBox control

  1. In Design view, right-click the ListBox control, and then click Show CommonControl Tasks****.

  2. On the Common DropDownList Tasks menu, click Edit Items.

  3. In the ListItem Collection Editor dialog box, click Add to add an item.

  4. In the ListItem properties area, set the Text and Value properties.

  5. Repeat steps 3 and 4 until you have added all the items you want.

See also

Concepts

DropDownList

Send feedback about this topic to Microsoft. © 2011 Microsoft Corporation. All rights reserved.