ASP.Net provides the controls: drop-down
list, list box, radio button list, check box list and Bulleted list.
These control let a user choose from one or more items from the list.
List boxes and drop-down list contain one or more list items. These
lists could be loaded either by code or by the List Item Collection Editor.
Basic syntax for list box control:
<asp:Listbox Id="Listbox1" runat="server" autopostback="true" OnSelectedIndexchanged="Listbox1_SelectedIndexChanged" </asp:listbox>
Basic syntax for a drop-down list control:
<asp:DropDownList
Id="Dropdownlist1: runat="server" autopostback="true" OnSelectedIndexchanged="Listbox1_SelectedIndexChanged" </asp:dropdownlsit>
Common Properties of List box and Drop-down Lists:
Items: The Collection of List item objects that represents the items in the control.this property returns an object of type list item collection
Rows: Specifies the number of items items displayed in the box.if actual list contains more than displayed then a scroll bar is added
Selected Index: The Index of the currently selected item.If more than one item is selected,then the index of the first selected item.if the no item is selected ,the value of this property is -1
Selected Value: The value of
the currently selected item. If more than one item is selected, then
the values of the first selected item. if no item is selected, the value of
this property is an empty string
Selected Mode: Indicates
whether a list box allows single selections or multiple selections.
Common Properties of each list item objects:
Property
|
Description
|
Text
|
The text displayed for the item
|
Selected
|
Indicates whether the item is
selected.
|
Value
|
A string value associated with the
item.
|
Note:
- To work with the items in a drop-down list or list box, you use the Items property of the control. This property returns a ListItemCollection object which contains all the items of the list.
- The SelectedIndexChanged event is raised when the user selects a different item from a drop-down list or list box.
No comments:
Post a Comment