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

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - 杨勇平

Oracle 的十八般武艺 台球常用术语解释以及英文对照 b/s开发常用javaScript技术 图片加水印 - 杨勇平 - 博客园 HTTP状态码及其含义 Split函数详解 - 杨勇平 - 博客园 ASP.NET分页组件学与用——教学篇 C#常用函数和方法集汇总 javascipt分页函数 Ajax实现无刷新三联动下拉框 慢慢的溜达 程序员贬值是个骗局! 警惕 男人难逃的五大"诱惑" 宽容 享受 - 杨勇平 人生中二十五件最重要的事情 asp.net+JSON+AJAX(基于prototype1.4)做无刷新的2级DropDownList 无题 证明题
GridView的小技巧(1)--如何实现鼠标划过改变GridView的行背景色
杨勇平 · 2006-12-31 · via 博客园 - 杨勇平

写一些简单的小技巧也许可以帮助大家把GridView用的更好,让GridView变得更漂亮更实用,大家都见过导航行栏上的这种效果,当鼠标停留在一个栏目上面,栏目的背景色就会改变,当鼠标移开栏目的背景色又还原回来,想想我们可以把这个效果用在GridView 上面,当我们把鼠标停留在记录行上面,背景颜色就改变,当我把鼠标移开的时候背景颜色就还原,下面我们就来看看怎么实现吧。

首先我们要先导入System.Drawing这个命名空间,接下来我们要编写GridView中的RowDataBound方法,看下面的代码:
   protected void gvType_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        int i;
        //执行循环,保证每条数据都可以更新
        for (i = 0; i < gvType.Rows.Count; i++)
        {
            //首先判断是否是数据行
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
                //当鼠标移开时还原背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            }
        }
    }

这样就可以简单实现我们所要的效果,是不是很简单。
大家如果有更好的方法可以写在评论里面,必定实现的方法不只一种。