下拉列表需要显示具有不同文本颜色的项目。颜色由服务器端决定。使用<style>
标签与CSS样式表。见例:
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;
}
从我在其他SO帖子中读到的有关格式化列表项文本的内容,我的一般程序似乎很接近。但我的ListItem总是黑色的。我错过了什么?
缩写HTML:
<style>
#employeeDropDownBox {
height: 65px;
width: 425px;
font-size: 27px;
margin-left: 5px;
}
</style>
<div>
<asp:DropDownList ID="employeeDropDownBox" runat="server" ></asp:DropDownList>
</div>
答案 0 :(得分:1)
不添加((foo(bar(baz)))(bat)(man))
,而是添加style
&amp;在css class
中使用此class
来处理颜色
css file
在你的css中:
li.Attributes.Add("class", "blue"); // you can use the `color` parameter as well
<强>更新强>
因此,您需要使用.blue {
color: blue;
}
代替:
=