Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Asp.net中更改下拉列表的颜色?_C#_Asp.net_Dropdown - Fatal编程技术网

C# 如何在Asp.net中更改下拉列表的颜色?

C# 如何在Asp.net中更改下拉列表的颜色?,c#,asp.net,dropdown,C#,Asp.net,Dropdown,我有一个下拉列表cboVendor,我想在下拉列表中输入数据 来自下面code中的ELSE部分的红色。但是问题 我是在if-else之后绑定数据的 .aspx <asp:DropDownList ID="cboVendor" runat="server" AppendDataBoundItems="True" AutoPostBack="true"> <asp:ListItem Value="0">- Select Vendor -</asp:ListItem>

我有一个下拉列表cboVendor,我想在下拉列表中输入数据 来自下面
code
中的
ELSE
部分的红色。但是问题 我是在if-else之后绑定数据的

.aspx

<asp:DropDownList ID="cboVendor" runat="server" AppendDataBoundItems="True"
AutoPostBack="true"> <asp:ListItem Value="0">- Select Vendor -</asp:ListItem>
</asp:DropDownList>

绑定数据后,您可以在列表项中循环,并可以像下面这样设置这些项的样式或类

  if(Checkbox.Checked!=true){
       foreach(ListItem item in cboVendor.Items) {   
                 item.Attributes.Add("style", "background-color:red;");  
     }  
   }

DDL在HTML中呈现为
Select
,因此您可以定义CSS类
供应商列表选项{color:red}
,并使用属性将该类分配给else块中的
cboVendor
;实际上,两个SP都返回不同的列集,我希望在其他部分显示红色。您可以在其上添加检查。您可以在其上添加检查。请回答此问题,然后接受此作为答案,以便其他人不会浪费时间阅读此问题
  if(Checkbox.Checked!=true){
       foreach(ListItem item in cboVendor.Items) {   
                 item.Attributes.Add("style", "background-color:red;");  
     }  
   }