惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园_首页
酷 壳 – CoolShell
酷 壳 – CoolShell
G
Google Developers Blog
Jina AI
Jina AI
C
Check Point Blog
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
Last Week in AI
Last Week in AI
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
阮一峰的网络日志
阮一峰的网络日志
The Cloudflare Blog
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
J
Java Code Geeks
WordPress大学
WordPress大学
博客园 - 聂微东
月光博客
月光博客
博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
大猫的无限游戏
大猫的无限游戏
Microsoft Security Blog
Microsoft Security Blog

博客园 - laughterwym

edwin-wang.com GridView vs DataGrid 来句老套的~~~Happy 牛 Year !!! Autopostback提示“该对象不支持此属性或方法”(Object doesn't support this property or method) Grub vga模式 个人常用软件替代列表,支持开源 One more time, One more chance 获得Access数据表名列表 初面纪念 关于Windows 2003 ".." 表示父路径解决方法 Windows 2003 SD读卡器驱动方法 关于水晶报表分页统计的开发经验 残败的考试 一段时间的忙碌…… Standards: big benefits for small business 国庆、中秋快乐!!! 2 weeks later 2周,开始忙碌中适应这里的生活了……累 I Do Believe
GridView mouseover的高亮
laughterwym · 2009-05-13 · via 博客园 - laughterwym

由于dotnet中获得到的RowStyle中color为System.Drawing.Color类的,所以首先需要将其转换成HTML能够接受的#xxxxxx形式。写了一个函数:

 1string toWebColor(System.Drawing.Color theColor)
 2{
 3if (Convert.ToString(theColor.R, 16== "0" && Convert.ToString(theColor.G, 16== "0" && Convert.ToString(theColor.B, 16== "0")
 4{
 5return "#ffffff";
 6}

 7else
 8{
 9return "#" + Convert.ToString(theColor.R, 16+ Convert.ToString(theColor.G, 16+ Convert.ToString(theColor.B, 16);
10}

11}

下边的程序就是个间隔行设置Attribute的行为:

 1if (e.Row.RowType == DataControlRowType.DataRow)
 2{
 3if (e.Row.RowState == DataControlRowState.Normal)
 4{
 5e.Row.Attributes.Add("onmouseover""this.style.backgroundColor='orange'");
 6e.Row.Attributes.Add("onmouseout""this.style.backgroundColor='" + toWebColor(GridView.RowStyle.BackColor) + "'");
 7}

 8else if (e.Row.RowState == DataControlRowState.Alternate)
 9{
10e.Row.Attributes.Add("onmouseover""this.style.backgroundColor='orange'");
11e.Row.Attributes.Add("onmouseout""this.style.backgroundColor='" + toWebColor(GridView.AlternatingRowStyle.BackColor) + "'");
12}

13else
14return;
15}