How to change DropDownList item background color in asp.net

asp.net dropdownlist item background color
dropdownlist-item-background-color.aspx

<%@ Page Language="C#" AutoEventWireup="true"%>  
    
<!DOCTYPE html>
      
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    { 
        if(!Page.IsPostBack)
        {
            string[] birds = { 
                                 "Southern Screamer",
                                 "Horned Screamer",
                                 "Swan Goose",
                                 "Greylag Goose",
                                 "Snow Goose",
                                 "Canada Goose",
                                 "Barnacle Goose",
                                 "Canada Goose",
                                 "Nene"
                             };

            DropDownList1.DataSource = birds;
            DropDownList1.DataBind();
        }
        string[] colors = {"snow","aliceblue","linen","cornsilk" };
        int index = 0;
        
        foreach (ListItem li in DropDownList1.Items)
        {
            string bg = "background-color:";
            bg += colors[index];

            li.Attributes.Add("style", bg);

            index++;
            if (index == colors.Count())
            {
                index = 0;
            }
        }
    }
</script>      
      
<html xmlns="http://www.w3.org/1999/xhtml">      
<head id="Head1" runat="server">      
    <title>asp.net dropdownlist item background color</title>
</head>      
<body>      
    <form id="form1" runat="server">      
    <div>      
        <h2 style="color:MidnightBlue; font-style:italic;">      
            asp.net example - dropdownlist item background color
        </h2>      
        <hr width="550" align="left" color="Gainsboro" />      
        <br /><br />
        <asp:DropDownList
            ID="DropDownList1"
            runat="server"
            AutoPostBack="true"
            Width="350"
            Font-Size="X-Large"
            >
        </asp:DropDownList>
    </div>      
    </form>      
</body>      
</html>
More asp.net examples