Asp.net DropDownList control


asp:DropDownList control

DropDownList control is used to give a single select option to the user from multiple listed items.


DropDownList control is utilized to give a solitary select alternative to the client from different recorded things. You can indicate its tallness and width in pixel by setting its stature and width however you won't be capable give mutliple select choice to the client. When it is rendered on the page, it is actualized through <select/> HTML tag. It is additionally called as Combo box. 



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

Following are some important properties that are very useful.

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 dropdown 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 
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:DropDownList ID="DropDownList1" 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:DropDownList>
                       
                        // 2nd DropDown box
                        <asp:DropDownList ID="DropDownList1" runat="Server" />
                       
                        // 3rd DropDown box
                        <asp:DropDownList ID="DropDownList1" runat="server" DataTextField="Name" DataValueField="ID" />
                       
                        // 4th DropDown box
                        <asp:DropDownList ID="DropDownList1" 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