GrideView选中和悬浮效果
2010-01-23 19:35 三皮开发时 阅读(312) 评论(0) 编辑 收藏 举报深色的是单击鼠标选中的,浅一点的是鼠标悬停在上面的,具体是:鼠标停在某行上是,该行自动变成上图所示的浅一些的背景色,单击的话,背景色变深,上次单击选中的行背景色恢复最初。
下面是代码:
protected void GvSelectResult_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("on
e.Row.Attributes.Add("on
e.Row.Attributes.Add("on
"this.style.backgroundColor='#b9cddd'");
//"var trs = this.parentNode.getElementsByTagName('tr');"+
// "for( i=1;i<trs.length;i++ )trs[i].style.backgroundColor='#ECF5FF';" +
}
}
说明,此代码全面兼容IE和FF。rgb(185, 205, 221)是#b9cddd在FF下的值,也就是上面深背景的颜色(鼠标单击后背景颜色),可以根据需要进行替换。#ECF5FF是上面浅一些的颜色(鼠标悬停时背景颜色),也可以根据需要替换。注意rgb(185, 205, 221)中间有空格,“,”后面有空格,不能去掉,否则FF下效果失效。用到了js全局变量window.selectedTr,window.trSelectedBgcolor,window.trSelectedBgcolor,有冲突时注意换变量名。
------转 吾心飞扬--http://hi.baidu.com/daijun2007/blog/item/d9dcfa111aadcc76ca80c491.html