asp.net - Change background color of a DropDownList programmatically

DropDownList Background Color
asp.net dropdownlist list web server control render a single selection list control in web page. .net developers can set or change the dropdownlist control's background color using its built in property BackColor. BackColor property get or set the background color of a web server control.

we can apply server control's BackColor property value using declarative syntax or dynamically in script section. to assign BackColor property value we need to use System.Drawing.Color type. here Color represents the background color. Color type exposes many members such as Yellow, DarkGreen, SeaGreen, White, Snow, Cyan etc.

the following c# example source code demonstrate us how can we set or change dropdownlist background color programmatically at run time in asp.net.
DropDownListBackColor.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        DropDownList1.BackColor = System.Drawing.Color.Crimson;
    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        DropDownList1.BackColor = System.Drawing.Color.SeaGreen;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>How to change DropDownList BackColor (background color) programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Green">DropDownList: Change BackColor</h2>
        <asp:Label 
             ID="Label1"
             runat="server"
             Font-Bold="true"
             ForeColor="DodgerBlue"
             Text="asp.net controls"
             >
        </asp:Label>
        <asp:DropDownList 
             ID="DropDownList1"
             runat="server"
             >
             <asp:ListItem>ListBox</asp:ListItem>
             <asp:ListItem>CheckBox</asp:ListItem>
             <asp:ListItem>Table</asp:ListItem>
             <asp:ListItem>XmlDataSource</asp:ListItem>
             <asp:ListItem>SqlDataSource</asp:ListItem>
        </asp:DropDownList>
        <br /><br />
        <asp:Button 
             ID="Button1"
             runat="server"
             Font-Bold="true"
             ForeColor="DodgerBlue"
             Text="Crimson BackColor"
             OnClick="Button1_Click"
             />
        <asp:Button 
             ID="Button2"
             runat="server"
             Font-Bold="true"
             ForeColor="DodgerBlue"
             Text="SeaGreen BackColor"
             OnClick="Button2_Click"
             />
    </div>
    </form>
</body>
</html>
More asp.net examples