Repeater控件中嵌套的table,实现单击行变色和单击行弹出页面

Comeonzhou 2010-11-15 09:59:16
1,单击第一行变色,然后点击第二行时,第一行恢复到初始颜色,第二行变色..前提是我不知道有多少行.每行都要实现这种效果
2.单击某行时 不仅变色,而且会弹出页面.
...全文
549 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
howtodown 2012-09-23
  • 打赏
  • 举报
回复
正好需要
luoliang0089 2011-10-26
  • 打赏
  • 举报
回复
学习中……
by_封爱 2010-11-15
  • 打赏
  • 举报
回复

/// <summary>
/// 双色表格以及光棒效果
/// </summary>
/// <param name="o">GridView的ID</param>
/// <param name="a">1 3 5 7 9 单行背景颜色</param>
/// <param name="b">2 4 6 8 10 双行背景颜色</param>
/// <param name="c">onmouseover 鼠标移动单个表格的颜色</param>
function senfe(o, a, b, c)
{
var t = document.getElementById(o)
if (t != null)
{
t = t.getElementsByTagName("tr");
for (var i = 1; i < t.length; i++)
{
t[i].style.backgroundColor = (t[i].sectionRowIndex % 2 == 0) ? a : b;
t[i].onclick = function()
{
this.x = "0";
this.style.backgroundColor = (this.sectionRowIndex % 2 == 0) ? a : b;
}
t[i].onmouseover = function()
{
if (this.x != "1")
this.style.backgroundColor = c;
}
t[i].onmouseout = function()
{
if (this.x != "1")
this.style.backgroundColor = (this.sectionRowIndex % 2 == 0) ? a : b;
}
}
}
}
//senfe("g1","#ECF9FC","#FFFFFF","#D6F1F8"); 调用

这个是GridView 你可以参考下 这个超级强大 而且兼容
如果你还想弹出的话 你在this.style.backgroundColor 后面写就行了
酷儿 2010-11-15
  • 打赏
  • 举报
回复
repeater的模版有交替项 就是奇偶之分 你直接用就OK了
孟子E章 2010-11-15
  • 打赏
  • 举报
回复
如果弹出窗口,再加上一行window.open即可
孟子E章 2010-11-15
  • 打赏
  • 举报
回复
参照
http://dotnet.aspx.cc/file/Change-GridView-Row-Background-Color-When-Click-Row.aspx
做法类似
Comeonzhou 2010-11-15
  • 打赏
  • 举报
回复
来个直接点的朋友啊..
我不需要鼠标移动变色 只需要点击变色和弹出窗口..
没办法 我技术有限...
天下在我心 2010-11-15
  • 打赏
  • 举报
回复
给 tr 添加一个onclick 的JS 方法,在方法里面改变背景色。这样试验下看看。
Comeonzhou 2010-11-15
  • 打赏
  • 举报
回复
百度 谷歌我还用得着你教啊. 楼上的不行 他那段我试过.
细嗅蔷薇 2010-11-15
  • 打赏
  • 举报
回复
都很简单啊 楼上的就行额 不行就百度 google 一下
telankes2000 2010-11-15
  • 打赏
  • 举报
回复

var S={
tempColorValue: { sBgColor: null, item_id: null, sColor: null, tempButtonBgColor: null },
changeBgColor: function(obj) { /*鼠標經過時的背景色*/
if (obj.id != this.tempColorValue.item_id) {
this.tempColorValue.sBgColor = obj.style.backgroundColor;
this.tempColorValue.sColor = obj.style.color;
obj.style.cursor = "pointer";
obj.style.backgroundColor = "#d0f3ff";
}
},
clearBgColor: function(obj) { /*鼠標離開后的背景色*/
if (obj.id != this.tempColorValue.item_id) {
obj.style.backgroundColor = this.tempColorValue.sBgColor;
obj.style.color = this.tempColorValue.sColor;
}
},
setBgColor: function(obj) { /*設置當前元素的背景色*/
obj.style.backgroundColor = "#3E94F1";
obj.style.color = "#fff";
var item_id = this.tempColorValue.item_id;
if (item_id != null) {
$(item_id).style.backgroundColor = this.tempColorValue.sBgColor; ;
$(item_id).style.color = this.tempColorValue.sColor;
}
if (item_id == obj.id) {
this.tempColorValue.item_id = null;
}
else {
this.tempColorValue.item_id = obj.id;
}
}
}
function Show(obj){
var url = "xxx.aspx?a="+obj;
window.showModalDialog(url,"","");
}


Repeater_DataBound:
e.Item.Attributes.Add("id",e.Item.ItemIndex.ToString());
e.Item.Attributes.Add("onclick","S.setBgColor(this);Show('001')");
e.Item.Attributes.Add("onmouseover","S.changeBgColor(this)");
e.Item.Attributes.Add("onmouseout","S.clearBgColor(this)");
Comeonzhou 2010-11-15
  • 打赏
  • 举报
回复
坐等高人#32
LiuK_Moon 2010-11-15
  • 打赏
  • 举报
回复
<tr onclick='CChange(<%# Eval("ID")%>,<%# Container.ItemIndex.ToString() %>)' id='<%# "tr"+Container.ItemIndex.ToString() %>'></tr>


<script type="text/javascript" language="javascript">
var num=false;
var curID=-1;
function CChange(id,showid)
{
if(curID==-1)
{
document.getElementById("tr"+showid).style.backgroundColor="#CCCCCC";
window.open('');
}
else
{
if(curID!=showid && curID!=-1)
{
document.getElementById("tr"+curID).style.backgroundColor="#FFFFFF";
num=false;
}

curID=showid;
if(!num)
{
num=true;
document.getElementById("tr"+curID).style.backgroundColor="#CCCCCC";
window.open();
}
}

}
</script>
LiuK_Moon 2010-11-15
  • 打赏
  • 举报
回复
楼主在否 我写了段JS给你用
jianshao810 2010-11-15
  • 打赏
  • 举报
回复
给 tr 添加一个onclick 的JS 方法,在方法里面改变背景色。这样试验下看看。
看见源代码就可以拉,不过,楼主要懂js
sunny_yu 2010-11-15
  • 打赏
  • 举报
回复
就是每行的onclick改变样式就行了。。
Comeonzhou 2010-11-15
  • 打赏
  • 举报
回复
忘了补充.弹出的窗口需要传选定某行的ID值.

62,039

社区成员

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

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

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

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