System.Web.UI.WebControls.ListBox Class

Represents a list box control that allows single or multiple item selection.

See Also: ListBox Members


public class ListBox : ListControl, System.Web.UI.IPostBackDataHandler


In this topic:


Use the System.Web.UI.WebControls.ListBox control to create a list control that allows single or multiple item selection. Use the ListBox.Rows property to specify the height of the control. To enable multiple item selection, set the ListBox.SelectionMode property to ListSelectionMode.Multiple.

To specify the items that you want to appear in the System.Web.UI.WebControls.ListBox control, place a ListItem element for each entry between the opening and closing tags of the System.Web.UI.WebControls.ListBox control.

Use the ListControl.Items collection to examine the System.Web.UI.WebControls.ListItem objects contained in the System.Web.UI.WebControls.ListBox control. For example, you can determine the selected item(s) in the System.Web.UI.WebControls.ListBox control by enumerating the ListControl.Items collection and testing the ListItem.Selected value for each System.Web.UI.WebControls.ListItem element.

The System.Web.UI.WebControls.ListBox control also supports data binding. To bind the control to a data source, first create a data source, such as one of the System.Web.UI.DataSourceControl objects, that contains the items to display in the control. Next, use the System.Web.UI.Control.DataBind method to bind the data source to the System.Web.UI.WebControls.ListBox control. Use the ListControl.DataTextField and ListControl.DataValueField properties to specify which field in the data source to bind to the Text and Value properties, respectively, of each list item in the control. The System.Web.UI.WebControls.ListBox control will now display the information from the data source.


This control can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. You can use validation controls to verify user input before displaying the input text in a control. ASP.NET provides an input request validation feature to block script and HTML in user input. For more information, see Securing Standard ControlsHow to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings, and Introduction to Validating User Input in ASP.NET Web Pages.


For information about how to configure this control so that it generates markup that conforms to accessibility standards, see Accessibility in Visual Studio 2010 and ASP.NET 4 and ASP.NET Controls and Accessibility.

Declarative Syntax




Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 1.0.5000.0,