【发布时间】:2017-08-23 05:47:03
【问题描述】:
我有一个下拉列表 cboVendor 我想将下拉列表中的数据放入 来自
ELSE的红色部分在下面的code.but 问题 是我在 if-else 之后绑定数据。
.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 类vendor-list option { color: red }并使用CssClass属性在 else 块中将此类分配给cboVendor。 -
写你的 else 块 cboVendor.BackColor = System.Drawing.Color.Red;