关于gridview列变色的问题
最近写了一个girdview,结合了js,可是设置了背景色的列在鼠标移动时,始终不能变色,请教各位大神帮助!图如下:
--------------------编程问答-------------------- JS部分
<script type="text/javascript">
function OnMouseOver(obj)
{
obj.style.backgroundColor="#0065CA";
}
function OnMouseOut(obj)
{
obj.style.backgroundColor = "White";
}
</script>
后台页面部分
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "OnMouseOver(this)");
e.Row.Attributes.Add("onmouseout", "OnMouseOut(this)");
}
} --------------------编程问答-------------------- e.Row.Attributes.Add("onMouseOver", "OnMouseOver(this)");
e.Row.Attributes.Add("onMouseOut", "OnMouseOut(this)"); --------------------编程问答-------------------- 背景色把变色部分遮住了。 --------------------编程问答--------------------
那能具体说下解决办法吗? --------------------编程问答-------------------- 双击GridView的OnRowDataBound事件;
在后台的GridView1_RowDataBound()方法添加代码,最后代码如下所示:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int i;
//执行循环,保证每条数据都可以更新
for (i = 0; i < GridView1.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");
}
}
} --------------------编程问答--------------------
按照你的代码修改后,有背景色的列还是不能变颜色,估计是被背景色给覆盖了,有别的办法解决下么?小弟真的不胜感谢!!! --------------------编程问答--------------------
有背景色的列还是不能变色啊 这是关键。。。 --------------------编程问答-------------------- 这个我一时也想不到合适的办法。
我有一个思路,你可以试试
你可以先将有背景色的列颜色去掉。
然后是鼠标移动时的对应行颜色改变事件。
再然后在给背景色添加上。
这样也行就不会被覆盖 --------------------编程问答-------------------- 别沉了啊 恳请大神们帮助下。。。 --------------------编程问答--------------------
js 部分写在<head></head>中的,GrdiView中的代码写在后台中的 --------------------编程问答--------------------
按照你的方法做了,但效果还是不行。兄弟真的快绝望了,能加QQ详谈吗,904108856. --------------------编程问答-------------------- 别沉了啊 有知道的牛人帮个忙啊 小弟感激不尽!!! --------------------编程问答-------------------- 不是的,你应该首先把背景色存起来,onmouseover时,用替换掉背景色,onouseout时,用回原来的颜色:
http://www.cnblogs.com/insus/archive/2012/10/29/2744769.html --------------------编程问答--------------------
整行的背景色可以变的 但是单独设置了某列的背景色 则没那个效果 请求帮助。。。 --------------------编程问答-------------------- CSDN的大神在哪里呀 莫非真的没办法解决了吗??? --------------------编程问答-------------------- refer this:
http://digitalcolony.com/lab/row-highlight/gridview.aspx --------------------编程问答--------------------
正解 --------------------编程问答-------------------- //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#ffffcd',this.style.fontWeight='';");
//当鼠标离开的时候 将背景颜色还原的以前的颜色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
这是行变色。。。列的准备去帮你研究,但是朋友叫我Dota去了。。下次补上。。Sorry --------------------编程问答--------------------
唉 我的重点是在行变色基础上,有背景色的列也能同时变色!
看来你很忙啊。。。
补充:.NET技术 , ASP.NET