DropDownList web server control
DropDownList is an ASP.NET web server control that enables user to select an item from a
predefined drop down list. List item only show when user click the drop down button. DropDownList
does not support multiple selection as like ListBox control. DropDownList is a container of list items.
ListItem have three properties Text, Value and Selected. Text specifies which are displayed in browser,
Value are hidden and associated with list item. Selected property indicate the specific ListItem are
currently selected or not. You can populate dropdownlist items from various DataSource. We can data bind
DropDownList at runtime.
DropDownList raises SelectedIndexChanged event when someone select an item from list. This cause PostBack to server if AutoPostBack set to true. So, we can show selected item's text and value immediately after someone select an item from DropDownLsit. The following example help you to better understand how DropDownList server control works in .NET Framework.
DropDownList raises SelectedIndexChanged event when someone select an item from list. This cause PostBack to server if AutoPostBack set to true. So, we can show selected item's text and value immediately after someone select an item from DropDownLsit. The following example help you to better understand how DropDownList server control works in .NET Framework.
DropDownListExample.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e) {
Label1.Text = "Your selected color is : " +
DropDownList1.SelectedItem.Text.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>How to use DropDownList control in asp.net</title>
</head>
<body style="padding:25px">
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
How to use DropDownList
</h2>
<hr width="450" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="Larger"
ForeColor="Crimson"
Font-Bold="true"
Font-Names="Comic Sans MS"
/>
<br /><br />
<asp:Label
ID="Label2"
runat="server"
Text="Select a color"
AssociatedControlID="DropDownList1"
Font-Bold="true"
ForeColor="Navy"
/>
<asp:DropDownList
ID="DropDownList1"
runat="server"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="true"
Width="350"
Font-Size="X-Large"
Font-Names="Comic Sans MS"
ForeColor="DarkBlue"
>
<asp:ListItem>AliceBlue</asp:ListItem>
<asp:ListItem>AntiqueWhite</asp:ListItem>
<asp:ListItem>Aqua</asp:ListItem>
<asp:ListItem>Aquamarine</asp:ListItem>
<asp:ListItem>Azure</asp:ListItem>
<asp:ListItem>Beige</asp:ListItem>
<asp:ListItem>Bisque</asp:ListItem>
<asp:ListItem>Black</asp:ListItem>
<asp:ListItem>BlanchedAlmond</asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>


- Validate a DropDownList control
- DropDownList AutoPostBack
- Populating a DropDownList from XmlDataSource
- ListBox
- Add an item to ListBox
- Removing ListBox item
- Populate a CheckBoxList from SqlDataSource
- Populate CheckBoxList from XmlDataSource
- CheckBoxList
- RadioButton
- RadioButtonList
- RadioButtonList control example