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

标签 c# css asp.net datatable dropdown

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/

相关文章:

c# - Windows 硬重启

jquery - Bootstrap Toggle 不适用于 onclick LI 元素

asp.net - 从 ASP.NET 标记设置 UserControl 属性值

c# - 添加 Azure Ad Oauth2 JWT token 声明

c# - System.Speech 降低麦克风灵敏度

html - 在 Internet Explorer 中使用 XSLT 和 CSS 处理 XML

html - 基本 HTML 文档中的 CSS 颜色更改

c# - 字符串未被识别为有效的日期时间

ASP.Net:Request.Form 元素的顺序是否已定义?

c# - .NET正则表达式: Get paragraphs