i have a dropdown cboVendor in which supplier name is coming now i want background colour to be red whose
fullyAgg
column(dt contains 11 columns in which fullagg is the 11th column
) is coming as Zero.currently i am doing as shown in the below code but it is taking all of them a zero(which should not happen)
.aspx
<asp:DropDownList ID="cboVendor" runat="server" AppendDataBoundItems="True"
AutoPostBack="true"> <asp:ListItem Value="0">- Select Vendor -</asp:ListItem>
</asp:DropDownList>
c#代码
DataTable dt = default(DataTable);
cboVendor.DataSource = dt;
cboVendor.DataTextField = "SupplierName";
cboVendor.DataValueField = "SupplierID";
cboVendor.DataBind();
cboVendor.SelectedIndex = 0;
foreach (ListItem item in cboVendor.Items) {
if (dt.Rows(10)("fullyAgg") == 0) {
item.Attributes.Add("style", "background-color:red;");
}
}
最佳答案
找到解决方案
DataView dv = dt.DefaultView;
dv.RowFilter = "fullyAgg=0";
foreach (DataRowView dr in dv) {
foreach (ListItem item in cboVendor.Items) {
if (dr("SupplierID").ToString() == item.Value.ToString()) {
item.Attributes.Add("style", "background-color:red;");
}
}
}
关于c# - 在运行时根据数据表 asp.net 的标志列更改下拉项的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45833622/