GridView行单击 变颜色

cherry_li 2009-11-27 09:01:11
GridView中实现的效果:

单击某一行,这行颜色变红绿色,再单击,颜色恢复到以前.

PS:单击变绿色,我已经可搞定,就是再单击恢复没有搞定.

if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "if(window.oldtr!=null){window.oldtr.runtimeStyle.cssText='';}this.runtimeStyle.cssText='background-color:green;window.oldtr=this");
}
...全文
190 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
cherry_li 2009-11-30
  • 打赏
  • 举报
回复
问题已经搞定.

cherry_li 2009-11-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 yaya_pei 的回复:]
.Add("onclick", "javascript:if(this.bgColor=='#c4d2ea'){this.bgColor='#F0F0E8'}else{this.bgColor='#c4d2ea';}")
                    .Add("onMouseOver", "javascript:if(this.bgColor!='#c4d2ea'){this.bgColor='#e0e0e0';}")
                    .Add("onMouseOut", "javascript:if(this.bgColor!='#c4d2ea'){this.bgColor='#F0F0E8';}")
[/Quote]

不可用
cherry_li 2009-11-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 juedaihuaihuai 的回复:]
再加一个时间 onblur的事件
[/Quote]

谢谢,能否贴出代码
cherry_li 2009-11-27
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 ynsky 的回复:]
呵呵.做过.
[/Quote]

......
YnSky 2009-11-27
  • 打赏
  • 举报
回复
呵呵.做过.
绝代坏坏 2009-11-27
  • 打赏
  • 举报
回复
再加一个时间 onblur的事件
Roger370 2009-11-27
  • 打赏
  • 举报
回复

function trclick(ck)
{
var cells = ck.getElementsByTagName("td");
if(ck.style.backgroundColor!="#00A9FF")
{
ck.style.backgroundColor="#00A9FF";
}
else
{
ck.style.backgroundColor = green;
}

}


e.Row.Attributes.Add("onclick", "javascript:trclick(this);");//点击行事件
Yaya_Pei 2009-11-27
  • 打赏
  • 举报
回复
.Add("onclick", "javascript:if(this.bgColor=='#c4d2ea'){this.bgColor='#F0F0E8'}else{this.bgColor='#c4d2ea';}")
.Add("onMouseOver", "javascript:if(this.bgColor!='#c4d2ea'){this.bgColor='#e0e0e0';}")
.Add("onMouseOut", "javascript:if(this.bgColor!='#c4d2ea'){this.bgColor='#F0F0E8';}")
randomfeel 2009-11-27
  • 打赏
  • 举报
回复
你都写出变颜色了,还不知道恢复啊?
其实就是两种颜色切换嘛

你if里判断一下当前的cssText,是A则换B,不是则换回A
不就这样嘛
cherry_li 2009-11-27
  • 打赏
  • 举报
回复

目前还没有看到可行的答案


请各位回复看清我的需求


谢谢
风骑士之怒 2009-11-27
  • 打赏
  • 举报
回复
up,一个if判断
qiushuangju 2009-11-27
  • 打赏
  • 举报
回复
henhao
brooklyng60 2009-11-27
  • 打赏
  • 举报
回复
protected void GrdPlanCheck_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "if(window.oldtr!=null){window.oldtr.runtimeStyle.cssText='';}this.runtimeStyle.cssText='background-color:#D1DDF1';window.oldtr=this;");
}
}
JackLeiMM 2009-11-27
  • 打赏
  • 举报
回复

//光棒效果
protected void gvffiche_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#dadada'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
}
}


cherry_li 2009-11-27
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 qq504769466 的回复:]
引用 9 楼 qq504769466 的回复:
protected void gvAdminShow_RowCreated(object sender, GridViewRowEventArgs e)
  {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onMouseOver", "javascript:if(this.bgColor!='Red'){this.bgColor='Red';}");
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onMouseOut", "javascript:if(this.bgColor!='White'){this.bgColor='White';}");
        }
    }



这个方法我刚才试过了,是可以用的,你试试
[/Quote]


这个不是我要的方法

我希望达到的效果是单击行,然后变颜色,再单击,就恢复到之前的颜色.
qq504769466 2009-11-27
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 qq504769466 的回复:]
protected void gvAdminShow_RowCreated(object sender, GridViewRowEventArgs e)
  {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onMouseOver", "javascript:if(this.bgColor!='Red'){this.bgColor='Red';}");
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onMouseOut", "javascript:if(this.bgColor!='White'){this.bgColor='White';}");
        }
    }
[/Quote]



这个方法我刚才试过了,是可以用的,你试试
qq504769466 2009-11-27
  • 打赏
  • 举报
回复
protected void gvAdminShow_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onMouseOver", "javascript:if(this.bgColor!='Red'){this.bgColor='Red';}");
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onMouseOut", "javascript:if(this.bgColor!='White'){this.bgColor='White';}");
}
}

62,254

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧