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

推荐订阅源

Forbes - Security
Forbes - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Palo Alto Networks Blog
Martin Fowler
Martin Fowler
T
Threatpost
D
Docker
S
Schneier on Security
M
MIT News - Artificial intelligence
G
Google Developers Blog
L
LINUX DO - 热门话题
J
Java Code Geeks
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
IT之家
IT之家
博客园 - Franky
C
Cyber Attacks, Cyber Crime and Cyber Security
K
Kaspersky official blog
Google DeepMind News
Google DeepMind News
N
News and Events Feed by Topic
V
Vulnerabilities – Threatpost
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
人人都是产品经理
人人都是产品经理
Spread Privacy
Spread Privacy
T
Tailwind CSS Blog
爱范儿
爱范儿
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
C
CERT Recently Published Vulnerability Notes
The GitHub Blog
The GitHub Blog
Simon Willison's Weblog
Simon Willison's Weblog
NISL@THU
NISL@THU
MongoDB | Blog
MongoDB | Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
H
Heimdal Security Blog
Recorded Future
Recorded Future
云风的 BLOG
云风的 BLOG
SecWiki News
SecWiki News
P
Privacy International News Feed
P
Proofpoint News Feed
O
OpenAI News
B
Blog
腾讯CDC
F
Full Disclosure
Apple Machine Learning Research
Apple Machine Learning Research
T
Tor Project blog
H
Hacker News: Front Page
Project Zero
Project Zero
Hugging Face - Blog
Hugging Face - Blog
C
Cisco Blogs
S
Security Affairs

博客园 - 流浪浪

使用递归的方法生产TreeView SQL截取字符串 SQL Server中各个系统表的作用 editor.js 缺少对象的解决方法(ewebeditor 使用) asp.net DataList中hyperlink传递参数及打开新页面全解 li:hover ul,li.over ul{ display: block;}这句被ie6.0解释不了 CSS + JavaScript 利用display:none/block 构造弹出菜单 23种设计模式的通俗理解 myeclipse9.0破解方法 C#弹出选择对话框的程序 sql语句中调用将汉字转换为拼音函数 sql将汉字首字转化为拼音 “IE7中Frameset页面显示不全”问题的原因与解决方案 (转) sql语句获取本周、本月数据 解决gridview导出到excel中汉字出现乱码的问题 - 流浪浪 - 博客园 (转)IT人士群聚喝酒 Better Man 倒春寒 恨铁不成钢啊!
vs2005 c#鼠标悬停高亮显示在gridview中
流浪浪 · 2011-12-02 · via 博客园 - 流浪浪

在girdview中的RowDataBound事件中写下如下代码: 

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='yellow';");
        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor;");
    }
}

有的时候,我们可能要根据需要,对gridview中的数据进行特殊的显示,比如当某样商品库存为0时,要求gridview中以不同颜色进行显示,这时,可以按如下的方法进行:

  首先,gridview提供了rowdatabound事件,该事件在gridview中每行被创建并且绑定到datasource控件后被触发,因此,我们可以利用该事件去检查库存是否为0,如果为0的话,将所在行的北京颜色设置为黄色,代码如下:

public void productsGridView_RowDataBound(object sender,

GridViewRowEventArgs e)

{

 if (e.Row.RowType == DataControlRowType.DataRow)

 {

  int unitsInStock = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "UnitsInStock"));

  if (unitsInStock == 0)

   e.Row.BackColor = Color.Yellow;

 }

}

  首先,该事件首先检查,当前的行是否属于datarow类型的行,因为象gridview中的headerrow,footerrow等行,并不包含实际的数据,因此,我们不需要使用headerrow和footerrow,而为了取得库存unitesinstock的内容,通过使用databinder.eval的方法取出其内容,并转换为int类型,接着判断是否为0,如果为0的话,则设置其行的背景颜色为黄色。