我有一个下拉cboVendor我想在下拉数据是在 红色是从
ELSE
一部分来在下面code
。但问题 是我结合后的数据的if-else。如何更改在Asp.net中下拉菜单的颜色?
的.aspx
<asp:DropDownList ID="cboVendor" runat="server" AppendDataBoundItems="True"
AutoPostBack="true"> <asp:ListItem Value="0">- Select Vendor -</asp:ListItem>
</asp:DropDownList>
C#代码
if (CheckBox1.Checked == true) {
cboVendor.DataSource = DAL.CertificationDA.GetFullAccreditedVendors(vendid);
cboVendor.DataTextField = "SupplierName";
cboVendor.DataValueField = "SupplierID";
} else {
cboVendor.DataSource = Supplier.GetSuppliersForSite(UserWrapper.GetCurrentUser.GetValidLocations.wsm_Ref_Buildings.FindByBuildingId(cboBuilding.SelectedValue).SiteId);
cboVendor.DataTextField = "SupplierName";
cboVendor.DataValueField = "SupplierID";
}
cboVendor.DataBind();
DDL以HTML呈现为'Select'所以可以定义一个CSS类'厂商列表选项{颜色:红}'和在其他块使用分配这个类'cboVendor' ['CssClass'](HTTPS:/ /msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.webcontrol.cssclass(v=vs.110).aspx)属性。 – niksofteng
撰写您else块 cboVendor.BackColor = System.Drawing.Color.Red; –