Skip to main content

Posts

Showing posts from 2016

Radio Button list and Check Box list

A radio button list presents a list of mutually exclusive options. A check box list presents a list of independent options. These controls contain a collection of ListItem objects that could be referred to through the Items property of the control. Basic syntax for radio button list: <asp:RadioButtonList ID="RadioButtonList1"     runat="server"    AutoPostBack="True"     OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"> </asp:RadioButtonList> Basic syntax for check box list: <asp:CheckBoxList ID="CheckBoxList1"     runat="server"     AutoPostBack="True"     OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged"> </asp:CheckBoxList>

The List Item Collections:

The ListItemCollection object is a collection of ListItem objects. Each ListItem object represents one item in the list. Items in a ListItemCollection are numbered from 0. When the items into a list box are loaded using strings like: lstcolor.Items.Add("Blue") . then both the Text and Value properties of the list item are set to the string value you specify. To set it differently you must create a list item object and then add that item to the collection. The ListItem Collection Editor is used to add item to a drop-down list or list box. This is used to create a static list of items. To display the Collection Editor select Edit item from the smart tag menu, or select the control and then click the ellipsis button from the Item property in the Properties window. Common Properties of List Item Collection: Property Description Item(integer) A ListItem object that represents the item at the specified index. Coun...

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. It is important to notes that: ·          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.

Common Properties of List box and Drop-down Lists:

Property Description Items The collection of ListItem objects that represents the items in the control. This property returns an object of type ListItemCollection. Rows Specifies the number of items displayed in the box. If actual list contains more rows than displayed then a scroll bar is added. SelectedIndex The index of the currently selected item. If more than one item is selected, then the index of the first selected item. If no item is selected, the value of this property is -1. SelectedValue The value of the currently selected item. If more than one item is selected, then the value of the first selected item. If no item is selected, the value of this property is an empty string(""). SelectionMode Indicates whether a list box allows single selections or multiple selections.

List Controls: List Box and Drop Downlist

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 ListItem 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="DropDownList1_SelectedIndexChanged"> </asp:DropDownList>