在asp.net数据表的标志列的基础上,在运行时更改下拉菜单项的背景色 [英] change background color of dropdown items at runtime on the basis of flag column of a datatable asp.net

查看:65
本文介绍了在asp.net数据表的标志列的基础上,在运行时更改下拉菜单项的背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个下拉菜单 cboVendor ,其中供应商名称即将到来
i希望背景颜色为红色,其 fullyAgg column (dt包含11列,其中fullagg是第11列)即将为零。下面的代码,但是将所有参数都设为零(不应该发生)

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;");
        }
    }
}

这篇关于在asp.net数据表的标志列的基础上,在运行时更改下拉菜单项的背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆