【问题标题】:How can I get background color of a selected item in checkboxlist如何获取复选框列表中所选项目的背景颜色
【发布时间】:2011-10-13 04:11:25
【问题描述】:

我正在使用复选框列表来绑定数据库中的一些数据。 checkboxlist 中的每个项目都设置有唯一的背景颜色。我需要将背景颜色设置为复选框列表中的选定项目。为了绑定颜色,我使用了下面的代码

for (int i = 0; i < cbFilter.Items.Count; i++)    
{
Color RandomColor = GetRandomColor();
string hexColorValue = ColorTranslator.ToHtml(RandomColor);
cbFilter.Items[i].Attributes.Add("style", "background-color:" + hexColorValue);
}

请给出一个解决方案来获取所选项目的背景颜色。

【问题讨论】:

    标签: c# .net asp.net styles checkboxlist


    【解决方案1】:
                foreach (ListItem  item in cbFilter.Items   )
                {
                    if (item.Selected)
                    {
                        Response.Write(item.Attributes.CssStyle["background-color"].ToString());
                    }
                }
    

    【讨论】:

    • 感谢您的回复。我试过了,但我得到了错误 Object reference not set to an instance of an object。
    • @user.net:请提供完整代码以便我提供合适的解决方案
    猜你喜欢
    • 1970-01-01
    • 2010-10-16
    • 1970-01-01
    • 2021-05-25
    • 1970-01-01
    • 2011-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多