asp.net dropdownlist selected item style
dropdownlist-selected-item-style.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
string[] birds = {
"Northern Shoveler",
"Brown Teal",
"Northern Pintail",
"Common Teal",
"Marbled Duck",
"Common Pochard"
};
DropDownList1.DataSource = birds;
DropDownList1.DataBind();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = "you selected....<br />";
Label1.Text += "item: " + DropDownList1.SelectedItem.Text;
Label1.Text += "<br />value: " + DropDownList1.SelectedItem.Value;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net dropdownlist selected item style</title>
<style type="text/css">
.select {
-webkit-border-radius:24px;
-moz-border-radius:24px;
border-radius:24px;
font-family:'Comic Sans MS';
}
.select option:checked {
background-color:deeppink;
color:snow;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
asp.net example - dropdownlist selected item style
</h2>
<hr width="550" align="left" color="Gainsboro" />
<asp:Label
ID="Label1"
runat="server"
Text="select an item from dropdownlist."
Font-Size="X-Large"
Width="350"
>
</asp:Label>
<br /><br />
<asp:DropDownList
ID="DropDownList1"
runat="server"
AutoPostBack="true"
Width="350"
Font-Size="X-Large"
CssClass="select"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
>
</asp:DropDownList>
</div>
</form>
</body>
</html>
- How to add attributes to DropDownList items
- How to add CSS class to DropDownList each items
- How to make DropDownList first item not selectable
- How to display tooltip for DropDownList each items
- How to create a rounded corners DropDownList
- How to remove arraow from DropDownList
- How to change DropDownList arrow image
- How to sort DropDownList items alphabetically
- How to sort DropDownList items by text
- How to sort DropDownList items by value