随笔 - 435  文章 - 0  评论 - 111  阅读 - 62万 

碰到一个需求,在下拉框里面有一项需要用红色表示,显得醒目一些。
一开始就想当然地写 dropdownlist1.attribute.add("style","color:red")
怎么试来试去都不行,然后用htmlselect来做却可以。
我想是不是dropdownlist1要用其他的方法来实现。第二天在csdn上查找
dropdownlist,颜色,发现其中有一篇提到,其中有两个连接
http://www.c-sharpcorner.com/Code/2003/July/DropDownListBox.asp
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q309338
才知道dropdownlist有一个bug,不支持Attribute,只能用htmlselect代替。
修改了一下自己的代码,例子代码如下:
        Dim ht As New Hashtable
 dim i as integer

        ht.Add("1", "red")
        ht.Add("2", "green")

        With dropdownlist1
            .DataValueField = "key"
            .DataTextField = "value"
            .DataSource = ht
            .DataBind()
            For i = 0 To .Items.Count - 1
                .Items(i).Attributes.Add("style", "color:" + .Items(i).Text)
            Next
        End With

posted on   Gu  阅读(1105)  评论(2编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
点击右上角即可分享
微信分享提示