gpt4 book ai didi

c# - 在运行时根据数据表 asp.net 的标志列更改下拉项的背景颜色

转载 作者:行者123 更新时间:2023-11-28 15:22:25 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com