积极答复者
gridview鼠标经过变色

问题
-
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='blue',this.style.fontWeight='700';");//当鼠标离开的时候 将背景颜色还原的以前的颜色e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='700';");}}请问该方法是不是错了(我的gridview没变色。),错了的话该怎么写鼠标经过的行变色。
- 已移动 肖小勇Moderator 2009年8月5日 7:22 ASP.NET 相关问题 (发件人:.NET Framework 一般性问题讨论区)
答案
-
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //当鼠标放上去的时候 先保存当前行的背景颜色并给附一颜色 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;w=this.style.fontWeight;this.style.backgroundColor='blue';this.style.fontWeight='700'"); //当鼠标离开的时候 将背景颜色还原的以前的颜色 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;this.style.fontWeight=w;"); } }
知识改变命运,奋斗成就人生!- 已标记为答案 孟宪会Moderator 2009年8月5日 12:43
全部回复
-
你好首先你得为每行定义一个currentcolor变量名不能一样比如根据e.Row.Index来建立变量 var v='var currentcolor_'"+e.Row.Index.ToString()+"'; eval(v);
还有这里的逗号
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor;this.style.fontWeight='700';");
Wenn ich dich hab’,gibt es nichts, was unerträglich ist.坚持不懈!http://hi.baidu.com/1987raymond -
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //当鼠标放上去的时候 先保存当前行的背景颜色并给附一颜色 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;w=this.style.fontWeight;this.style.backgroundColor='blue';this.style.fontWeight='700'"); //当鼠标离开的时候 将背景颜色还原的以前的颜色 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;this.style.fontWeight=w;"); } }
知识改变命运,奋斗成就人生!- 已标记为答案 孟宪会Moderator 2009年8月5日 12:43
-
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onMouseOver", "this.style.background='#FFFFBF'");
e.Row.Attributes.Add("onMouseOut", "this.style.background='#FFFFFF'");
}
}
你好,请参考!
jon.valett@gmail.com