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.
SelectedValue | Get the value of the Selected item from the dropdown box. |
SelectedIndex | Gets or Sets the index of the selected item in the dropdown box. |
SelectedItem | Gets the selected item from the list. |
Items | Gets the collection of items from the dropdown box. |
DataTextField | Name 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.) |
DataValueField | Name 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.) |
DataSourceID | ID of the datasource component to provide data. (Only used when you have any DataSource component on the page, like SqlDataSource, AccessDataSource etc.) |
DataSource | The datasource that populates the items in the dropdown box. (Generally used when you are dynamically generating the items from Database.) |
AutoPostBack | true 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. |
AppendDataBoundItems | true 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. |
OnSelectedIndexChanged | Method 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 code | Added 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" />
0 comments:
Post a Comment