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

推荐订阅源

WordPress大学
WordPress大学
小众软件
小众软件
MongoDB | Blog
MongoDB | Blog
Hugging Face - Blog
Hugging Face - Blog
Jina AI
Jina AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
大猫的无限游戏
大猫的无限游戏
量子位
A
About on SuperTechFans
G
Google Developers Blog
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Vercel News
Vercel News
V
Visual Studio Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
U
Unit 42
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - 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}