Dropdown list needs to display items with varying text colors. Color is decided by server-side. Uses <style> tags versus CSS styling sheet. See example:
protected void Page_Load(object sender, EventArgs e)
{
ListItem li = CreateListItemWithColor("Hello", "myValue", "blue");
employeeDropDownBox.Items.Add(li);
}
public ListItem CreateListItemWithColor(string text, string value, string color)
{
//Create the list item based on input text/value
ListItem li = new ListItem();
li.Text = text;
li.Value = value;
li.Attributes.Add("style", "color="+color);
return li;
}
From what I have read in other SO posts about formatting list item text, my general procedure seems close. But my ListItem is always black. What am I missing?
Abbreviated HTML:
<style>
#employeeDropDownBox {
height: 65px;
width: 425px;
font-size: 27px;
margin-left: 5px;
}
</style>
<div>
<asp:DropDownList ID="employeeDropDownBox" runat="server" ></asp:DropDownList>
</div>
optionelements in aselecteven could be styled. That's always been an issue in web development, since different hosts renderselectelements their own way. Generally the solution has been to use JavaScript plugins to create custom elements which mimic the behavior of aselectand synchronize with a hiddenselect.<style>tags successfully.