The ListBox control allows you to display a single-select or multi-select listbox.
Required properties are noted in boldface type.
<asp:ListBox id="Listbox1" runat="server" DataSource="<% databindingexpression %>" DataTextField="DataSourceField" DataValueField="DataSourceField" AutoPostBack="True|False" Rows="rowcount" SelectionMode="Single|Multiple" OnSelectedIndexChanged="OnSelectedIndexChangedMethod" /> <asp:Listitem value="value" selected="True|False"> Text </asp:Listitem> </SP:ListBox>
Property | Description |
---|---|
(Base control properties) | The properties defined in Base Web Control Properties. |
AutoPostBack | True if client-side changes in the control automatically cause a postback to the server; false otherwise. The default is false. |
DataTextField | The field or property of the object in DataSource that will be the source of data for the Text property of individual list items. |
DataValueField | The field or property of the object in DataSource that will be the source of data for the Value property of individual list items. |
DataSource | A data-binding expression that references any object that supports the ICollection interface.
Note In ASP+ syntax, it is preferable to include the data-binding expression in single quotation marks to accommodate quoted expressions. |
Items | A collection of ListItem objects representing individual items within the drop-down list.
This property is only used when programming. At design time, you set this property by declaring <asp:ListItem> items. |
SelectedIndex | The ordinal index of the currently selected item in the drop-down list.
This property is only used when programming. At design time, you set this property by including a Selected property in a ListItem element. |
SelectedItem | A reference to the Value property of the currently-selected item in the list.
This property is only used when programming. At design time, you set this property by including a Selected property in a ListItem element. |
SelectedItems | The collection of ListItem objects currently selected. If SelectionMode is set to Single, this collection contains the same item as SelectedItem.
This property is only used when programming. At design time, you set this property by including a Selected property in a ListItem element. |
Rows | The number of rows to display. |
SelectionMode | Single if the user can select only one item; Multiple if the user can hold down SHIFT or CTRL while clicking to select multiple items.
When programming, you set this property using the ListBoxSelectionMode enumeration. |
Property | Description |
---|---|
Selected | true if the item is the one selected in the drop-down list and that appears in the text box; false otherwise. Only one item can be declared as selected. |
Text | The text that appears in the list. This property is for display; the Value property contains the actual selection. |
Value | The value of the item selected by the user, which can be different from the text displayed in the list. This property is the one available in the SelectedItem property of the DropDownList control. |
Event (and paramters) | Description |
---|---|
OnSelectedIndexChanged(Object sender, EventArgs e) | Raised on the server when the selection of the ListBox control changes. This event does not cause the Web Forms page to be posted to the server unless the AutoPostBack property is set to true.
The e events argument object has no properties. |
To be supplied.
See Also