C# .NET - changing color of items text in DropDownList

Asked By Vladimir Peric on 10-Sep-05 06:07 PM
I try to change color of every item in my DropDownList. Was try on DataBound, and PreRender, but it doesn't work. Problem is becouse i can't add any atribute to <option>. I try in debuger, and attributes are added, but they don't show HTML. I try to change item.Text, and it works. So :) ?
I have piece code like this:
    public void ddlColors_DataBound(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        foreach (ListItem item in ddl.Items)
        {
            item.Attributes.Add("style", "color:" + item.Text.Trim());
            item.Text = "text";
        }
     }

That is correct

Asked By Peter Bromberg on 10-Sep-05 06:27 PM
The HTML "option" element does not accept attributes.
Remember, whatever you do in ASP.NET on the server side (or even on the client side) it all ends up as HTML.

You can do this with OmniPotent Rich Dropdown

Asked By Phillip Gerrish on 10-Sep-05 08:05 PM
I had to do something similar for a project I was doing.  I used the Rich Dropdown from Omnipotent (http://www.omnipotent-software.com/OPRDDDemo.aspx).  It worked good and was simple.  The only draw back I found was it increased the page size compared to a normal drop down.  If your list is small it will probably not have much imact on your page.

Here's a simple example

Asked By Peter Bromberg on 10-Sep-05 09:38 PM
of how this can be done with CSS and without 3rd party controls:
<style> 
.option {
background-color:lightblue;
} 
.option2 {
background-color:gray;
} 
</style>
<BODY>
<Select id=test>
<Option class="option">test</option>
<Option class="option2">test2</option>
<Option class="option">test3</option>
</select>
all you help me, thanks a lot !!!!!!!!!
Asked By Vladimir Peric on 12-Sep-05 04:26 AM
.