且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在下拉列表的每一行中添加颜色。

更新时间:2023-12-01 15:18:16

请参阅以下链接



使用C#的多色DropDownList [ ^ ]



-------------------





Refer below link

Multi-color DropDownList using C#[^]

-------------------
OR

<asp:DropDownList ID="DropDownList1" AppendDataBoundItems="true" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" OnLoad="DropDownList1_Load">
        <asp:ListItem Value="-1">Select</asp:ListItem>
        <asp:ListItem Value="0">Red</asp:ListItem>
        <asp:ListItem Value="1">Blue</asp:ListItem>
        <asp:ListItem Value="2">Green</asp:ListItem>
        <asp:ListItem Value="3">Violet</asp:ListItem>
</asp:DropDownList>










protected void DropDownList1_Load(object sender, EventArgs e)
{
        for (int i = 0; i < DropDownList1.Items.Count; i++)
        {
            DropDownList1.Items[i].Attributes.Add("styleackground-color:" + DropDownList1.Items[i].Text);
           
        }
}