如何使DropDownList项的最高价值Bold C#

时间:2012-04-26 21:13:05

标签: c# visual-studio-2008 webforms

我有这个下拉列表,我需要将最高值设为粗体。我该怎么做?

ddlDefaultSkins = new DropDownList();
ddlDefaultSkins.ID = "ddlDefaultSkins";
ddlDefaultSkins.ToolTip = "Select Default Clock Skin";
ddlDefaultSkins.SelectedValue = "CustomClock";
ddlDefaultSkins.AutoPostBack = true;

ddlDefaultSkins.Width = Unit.Pixel(100);
ddlDefaultSkins.Items.Add("CustomClock");
ddlDefaultSkins.Items.Add("swissRail");
ddlDefaultSkins.Items.Add("chunkySwiss");
ddlDefaultSkins.Items.Add("fancy");
ddlDefaultSkins.Items.Add("machine");
ddlDefaultSkins.Items.Add("classic");

2 个答案:

答案 0 :(得分:3)

也许你可以使用:

var item = new ListItem("CustomClock");
item.Attributes.Add("style", "font-weight: bold");

ddlDefaultSkins.Items.Add(item);

答案 1 :(得分:-2)

foreach (ListItem item in DropDownList1.Items)
{
    //if you want to apply for some selected items check the condition on item.Text or item.Value based on your requirement.
    if (item.Text == "Some Value")
    {
        //Change font weight 
        item.Attributes.CssStyle.Add("font-weight", "bold");
        //Change font color
        item.Attributes.CssStyle.Add("color", "red");
    }
}