纸上得来终觉浅,绝知此事要躬行。

 

鼠标移到Gridview的行上面,当前行变颜色

首先要为GridView添加RowDataBound事件,如下图

然后为后台*.aspx.cs文件添加如下代码:

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

 

 接下来最重要了,那就是看效果。。。添加if语句是为了不让列标题变颜色。如果不加if语句,那么列标题也会变颜色,效果就很难看了

posted on 2010-10-13 13:31  JRoger  阅读(819)  评论(0)    收藏  举报

导航