W e b t u t o r i a l s

Website

Intro to ASP.NET

ASP.NET Web Forms

Standard Controls

Label Control

TextBox Control

Image Control

Button Controls

Redirecting User

Using HyperLinks

RadioButton Control

RadioButtonList

CheckBox Control

CheckBoxList Control

DropDownList

ListBox Control

ImageMap Control

Master Page

View State

Event-Driven Programming

IsPostBack

Structure of an ASP.NET Page

Visibility of Controls

Formatting Controls

Applying CSS

Dynamic CSS

Using Style Class

Themes and Skins

Panel Control

PlaceHolder Control

AdRotator Control

Calendar Control

Validation Controls

Page Navigation

User Control

Separating Code From Presentation

Overview of ADO.NET

Data Binding

Binding Data to a List Control

ListBox Control in ASP.NET

It provides the user with a list of options out of which the user can select only one or multiple items at a time depending upon how the list box has been configured.

The properties, methods, and events of this control are listed in Table
Property Description
Items Represents the collection of items in the list box.
AutoPostBack If True, the form is automatically posted when a new option is selected from the list box.
SelectedItem Represents the selected option.
SelectedIndex Specifies the index number of currently selected option.
SelectionMode Determines whether a user can select more than one list item. Possible values are Single and Multiple.
Rows Indicates the number of rows to display in the list box. Default is 4.
DataSource Identifies the data source for the items listed in the list box.
DataMember Identifies the particular table in a data source to bind to the control.
DataTextField Identifies the field from the data source to use for option text.
DataValueField Identifies the field from the data source to use for option values.
DataTextFormatString Gets or sets a format string that determines how DataTextField is displayed.
Methods Description
DataBind Binds the list box to a data source. Loads items from data source into the ListItemCollection collection.
OnSelectedIndexChanged Raises the SelectedIndexChanged event.
Events Description
SelectedIndexChanged Raised when a new option is selected in the list box.

You can add options in the list box in the same 3 ways as for other list control.
If you wish to enable the user to select more than one option at a time, set the SelectionMode property to the value Multiple. The user can use the Shift or Ctrl keys to select multiple options.
You can determine a single selected option by using either the SelectedIndex or the SelectedItem property. In case of multiple selections, these properties return information only for the first selected item. To determine all selected items, iterate through the ListItemCollection and check the Selected property of each item.
Output