简体   繁体   English

颜色下拉列表项中的错误

[英]Error in color drop down list items

I have the following method which add an items to drop down list in run time. 我有以下方法,可以在运行时将项目添加到下拉列表中。 It is add the items good, but items appears without any style 是添加好的商品,但商品没有任何样式出现

Here the drop down list 这里的下拉列表

<asp:DropDownList ID="ddlColorPicker" runat="server">                   
</asp:DropDownList>

And here the method that i call to add items on page-load 这是我调用的用于在页面加载时添加项目的方法

protected void fillDDLFilesTypesColor()
    {           
        ListItem l1 = new ListItem("بلا لون", "");
        l1.Attributes.Add("style", "color:red");
        l1.Attributes.Add("style", "background-color:#111111");

        ListItem l2 = new ListItem("أحمر", "red");
        l2.Attributes.Add("style", "color:red");
        l2.Attributes.Add("style", "background-color:#111111");            

        ListItem l3 = new ListItem("أزرق", "blue");
        l3.Attributes.Add("style", "color:blue");
        l3.Attributes.Add("style", "background-color:#00FF7F");

        ListItem l4 = new ListItem("أخضر", "green");
        l4.Attributes.Add("style", "color:green");
        l4.Attributes.Add("style", "background-color:#00FF7F");

        ListItem l5 = new ListItem("أصفر", "yellow");
        l5.Attributes.Add("style", "color:yellow");
        l5.Attributes.Add("style", "background-color:#111111");

        ddlColorPicker.Items.Add(l1);
        ddlColorPicker.Items.Add(l2);
        ddlColorPicker.Items.Add(l3);
        ddlColorPicker.Items.Add(l4);
        ddlColorPicker.Items.Add(l5);
    }

You are overwriting your style. 您正在覆盖自己的风格。 Do it all in one line, like: 一行完成所有操作,例如:

ListItem l2 = new ListItem("أحمر", "red");
l2.Attributes.Add("style", "background-color:#111111; color:red;");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM