Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
how to put  color-in each row of a drop down list. Using data stored in SQL Server.
Posted
Comments
Richard MacCutchan 25-Jan-16 6:03am    
You have tagged this C#, HTML5, and SQL-Server: so which one do you mean, and what coding are you trying to use?
dan!sh 25-Jan-16 6:03am    
What have you tried so far? How do you want to color your drop down? Alternating colors? Is there any business logic that defines the colors of items in the drop down? Can you share the HTML/JS code you have?

Can you see how little information you have provided here?
Joandro 25-Jan-16 6:10am    
I have a table that holds the names of colors in the database , but would like to be presented at the Dropdown was the kind of color and not the color name .
Joandro 25-Jan-16 6:14am    
i dont know where i will start
Richard MacCutchan 25-Jan-16 6:55am    
You start by defining your list and what language you are using to display it. As I asked earlier, is this C#, HTML ... what? Please edit your question and add some proper detail about what you are trying to do.

1 solution

Refer below link

Multi-color DropDownList using C#[^]

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

ASP.NET
<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>



C#
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);
           
        }
}
 
Share this answer
 
Comments
Joandro 25-Jan-16 7:35am    
thanks for your help!!
I want something like link shows.
i will study it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900