How to add CSS class to DropDownList each items in asp.net

asp.net dropdownlist attributes
dropdownlist-attributes.aspx

<%@ Page Language="C#" AutoEventWireup="true"%>  
    
<!DOCTYPE html>
      
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    { 
        if(!Page.IsPostBack)
        {
            string[] birds = { "Emu", "Brown Kiwi", "Malleefowl", "Maleo", "Helmeted Guineafowl" };
            DropDownList1.DataSource = birds;
            DropDownList1.DataBind();
        }
        for (int i = 0; i < DropDownList1.Items.Count;i++)
        {
            if (i % 2 == 0)
            {
                DropDownList1.Items[i].Attributes.Add("class", "even");
            }
            else
            {
                DropDownList1.Items[i].Attributes.Add("class", "odd");
            }
        }
    }
</script>      
      
<html xmlns="http://www.w3.org/1999/xhtml">      
<head id="Head1" runat="server">      
    <title>asp.net dropdownlist attributes</title>
    <style type="text/css">
        .even {
            color:red;
            background-color:snow;
        }
        .odd {
            color:blue;
            background-color:aliceblue;
        }
    </style>
</head>      
<body>      
    <form id="form1" runat="server">      
    <div>      
        <h2 style="color:MidnightBlue; font-style:italic;">      
            asp.net example - dropdownlist attributes
        </h2>      
        <hr width="550" align="left" color="Gainsboro" />      
        <br /><br />
        <asp:DropDownList
            ID="DropDownList1"
            runat="server"
            AutoPostBack="false"
            Width="350"
            Font-Size="X-Large"
            >
        </asp:DropDownList>
    </div>      
    </form>      
</body>      
</html>
More asp.net examples