Export (0) Print
Expand All

ListBox Class

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

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

[ValidationPropertyAttribute(L"SelectedItem")] 
public ref class ListBox : public ListControl, IPostBackDataHandler
/** @attribute ValidationPropertyAttribute("SelectedItem") */ 
public class ListBox extends ListControl implements IPostBackDataHandler
ValidationPropertyAttribute("SelectedItem") 
public class ListBox extends ListControl implements IPostBackDataHandler
Not applicable.

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

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

Caution noteCaution:

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.

Accessibility

The markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.

TopicLocation
How to: Respond to Changes in List Web Server ControlsBuilding ASP .NET Web Applications
How to: Set Focus on ASP.NET Web Server ControlsBuilding ASP .NET Web Applications
How to: Determine the Selection in List Web Server ControlsBuilding ASP .NET Web Applications
How to: Add ListBox Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Populate List Web Server Controls from a Data SourceBuilding ASP .NET Web Applications
How to: Add Items in List Web Server ControlsBuilding ASP .NET Web Applications
How to: Set the Selection in List Web Server ControlsBuilding ASP .NET Web Applications
How to: Respond to Changes in List Web Server ControlsBuilding ASP .NET Web Applications
How to: Set Focus on ASP.NET Web Server ControlsBuilding ASP .NET Web Applications
How to: Determine the Selection in List Web Server ControlsBuilding ASP .NET Web Applications
How to: Add ListBox Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Populate List Web Server Controls from a Data SourceBuilding ASP .NET Web Applications
How to: Add Items in List Web Server ControlsBuilding ASP .NET Web Applications
How to: Set the Selection in List Web Server ControlsBuilding ASP .NET Web Applications
Walkthrough: Creating Reusable Elements with ASP.NET User ControlsBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio
How to: Set the Selection in List Web Server Controls (Visual Studio)Building ASP .NET Web Applications in Visual Studio
How to: Add ListBox Web Server Controls to a Web Forms Page (Visual Studio)Building ASP .NET Web Applications in Visual Studio
How to: Populate List Web Server Controls from a Data Source (Visual Studio)Building ASP .NET Web Applications in Visual Studio
Walkthrough: Data Binding to a Custom Business ObjectBuilding ASP .NET Web Applications in Visual Studio
How to: Add Items in List Web Server Controls (Visual Studio)Building ASP .NET Web Applications in Visual Studio

The following example demonstrates how to create a ListBox control.

No code example is currently available or this language may not be supported.

The following example demonstrates how to create a ListBox control through data binding.

No code example is currently available or this language may not be supported.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft