C#中 给DropdownList中 的item 字体 或这背景添加不同的颜色

来源:百度知道 编辑:UC知道 时间:2024/05/05 07:53:27
如题
请教高手!!!
css文件 怎么给dropdownlist 加上? 一楼的可以 只是我 要用服务器控件

Frist:
Changed you Control [DropDownList]

<SELECT id="DropDownList1" name="DropDownList1" runat="server"></SELECT>

and in .cs

for (int i =0;i < DropDownList1.Items.Count ;i++ )
{
if(DropDownList1.SelectItem.Text="Changs"
DropDownList1.Items[i].Attributes.Add("style", "color:#3366cc");//chang fontcolor
DropDownList1.Items[i].Attributes.Add("style", "background-color:#3366cc");//chang backcolor

}

最简单美观的就是CSS

直接上css文件即可。

带地是winform 的还是webform的啊
上面的是webform的,肯定可行的
winform的有BackColor属性和ForeColor属性,可以选择的