Asp.net ListBox control



asp:ListBox control

ListBox control is utilized to give a solitary or various select choices to the client from different recorded things.

All properties and its working takes after DropDownList box. Notwithstanding, ListBox has two additional properties called Rows and SelectionMode. ListBox control is utilized to give a solitary or different select choice to the client (in light of the property set) from various recorded things. You can determine its tallness and width in pixel by setting its stature and width however you won't be capable give mutliple select alternative to the client. When it is rendered on the page, it is executed through <select/> HTML tag. It is additionally called as Combo box.

Its properties like BackColor, ForeColor and so on are actualized through style properites of <span>. It has less property to enhance in correlation with different controls. There is no property like BorderStyle, BorderWidth. in DropDownList control.

You can include its alternative things by straightforwardly composing into .aspx page specifically or powerfully include at run time or tie through database.


Following are some important properties that are very useful.
RowsNo. of rows (items) can be set to display in the List.
SelectionModeSingle or Multiple. If multiple, it allows user to select multiple items from the list by holding Ctrl or Shift key.
SelectedValueGet the value of the Selected item from the dropdown box.
SelectedIndexGets or Sets the index of the selected item in the dropdown box.
SelectedItemGets the selected item from the list.
ItemsGets the collection of items from the dropdown box.
DataTextFieldName of the data source field to supply the text of the items. (No need to set when you are adding items directly into .aspx page.)
DataValueFieldName of the data source field to supply the value of the items. (No need to set when you are adding items directly into .aspx page.)
DataSourceIDID of the datasource component to provide data. (Only used when you have any DataSource component on the page, like SqlDataSource, AccessDataSource etc.)
DataSourceThe datasource that populates the items in the listbox box. (Generally used when you are dynamically generating the items from Database.)
AutoPostBacktrue or false. If true, the form is automatically posted back to the server when user changes the dropdown list selection. It will also fire OnSelectedIndexChanged method.
AppendDataBoundItemstrue or false. If true, the statically added item (added from .aspx page) is maintained when adding items dynamically (from code behind file) or items are cleared.
OnSelectedIndexChangedMethod name that fires when user changes the selection of the dropdown box. (Fires only when AutoPostBack=true.)

Staically added items (from .aspx page)Added manually through codeAdded through databound (dynamically)
1st DropDown box: 2nd DropDown box 3rd DropDown box  (Multiple selction is possible, hold Ctrl or Shift key and click items.)
This DropDown will fire OnSelectedIndexChanged event when you select other item.
4th DropDown box 
Note: When dropdown box item changes, Values of dropdowns will appear here in the selected color of 1st dropdown box.

Example -

// 1st DropDown box
                        <asp:ListBox ID="ListBox1" runat="server">
                            <asp:ListItem Text="Red" Value="red"></asp:ListItem>
                            <asp:ListItem Text="Blue" Value="blue"></asp:ListItem>
                            <asp:ListItem Text="Green" Value="green"></asp:ListItem>
                        </asp:ListBox>
                       
                        // 2nd DropDown box
                        <asp:ListBox ID="ListBox1" runat="Server" />
                       
                        // 3rd DropDown box
                        <asp:ListBox ID="ListBox2" runat="server" DataTextField="Name" DataValueField="ID" Rows="8" SelectionMode="multiple" />
                       
                        // 4th DropDown box
                        <asp:ListBox ID="ListBox3" runat="server" DataTextField="Name" DataValueField="ID" OnSelectedIndexChanged="GivePostBackResult" AutoPostBack="True" />
Share on Google Plus

About It E Research

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment