javascript如何获取GridView某行索引

有你_才有梦想 2007-02-12 02:53:32
我在GridView放了一列模版列(按钮),现在想用javascript获取当前行的索引值
这个怎么做啊
...全文
1128 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
beckhon 2011-11-04
  • 打赏
  • 举报
回复
新手mark
Xuon 2010-04-13
  • 打赏
  • 举报
回复
老孟的怎么报错。
在看这个:<table id= "table1 ">
<tr>
<td>
<input name= "file1 " type= "file ">
</td>
<td>
<input type= "button " value= "行号 " onclick=alert(this.parentNode.parentNode.rowIndex+parseInt(1))>
</td>
</tr>
<tr>
<td>
<input name= "file1 " type= "file ">
</td>
<td>
<input type= "button " value= "行号 " onclick=alert(this.parentNode.parentNode.rowIndex+parseInt(1))>
</td>
</tr>
<tr>
<td>
<input name= "file1 " type= "file ">
</td>
<td>
<input type= "button " value= "行号 " onclick=alert(this.parentNode.parentNode.rowIndex+parseInt(1))>
</td>
</tr>
<tr>
<td>
<input name= "file1 " type= "file ">
</td>
<td>
<input type= "button " value= "行号 " onclick=alert(this.parentNode.parentNode.rowIndex+parseInt(1))>
</td>
</tr>
</table>

http://topic.csdn.net/u/20070312/17/3a4a19e2-52b6-4ae1-bc36-42f3b5ef70c0.html
  • 打赏
  • 举报
回复
可以了,谢谢孟老大和其他大哥
跟大家学到了很多东西
dongfangbai 2007-02-13
  • 打赏
  • 举报
回复
mark!!!
孟子E章 2007-02-13
  • 打赏
  • 举报
回复
GridView最终生成的都是table,不可能没有TR的.

<script>
function getIt(obj) {
var r,c
o = obj
while(o.tagName != "TD" && o.tagName != "TH")
o = o.parentNode
if(o.tagName != "TD" && o.tagName != "TH") return
c = o.cellIndex
while(o.tagName != "TR")
o = o.parentNode
if(o.tagName != "TR") return
r = o.rowIndex
document.getElementById("label1").innerHTML=(r + " : " +c)
}
</script>
<div id=label1></div>
<table>
<tr>
<th></th><th> c<input type=button onclick="getIt(this)"></th>
</tr>
<tr>
<td></td><td> c<input type=button onclick="getIt(this)"></td>
</tr>
<tr>
<td></td><td> c<input type=button onclick="getIt(this)"></td>
</tr><tr>
<td></td><td> c<input type=button onclick="getIt(this)"></td>
</tr><tr>
<td></td><td> c<input type=button onclick="getIt(this)"></td>
</tr>
</table>
  • 打赏
  • 举报
回复
这样做还是不行的啊
因为按钮是GridView里的绑定列,没有<tr>,所以也没有办法根据TR对象找rowIndex
whoisyoung 2007-02-12
  • 打赏
  • 举报
回复
找到该行的<tr>后 取 TR对象.rowIndex
  • 打赏
  • 举报
回复
这个问题可能是我没有描述清楚,楼上的两位大哥做的不是我想实现的功能
我重新说一下吧


现在我的GridView有三列,第一列和第二列是绑定列,第三列是模版列,模版列放的是按钮
要求是用javascript实现
点击模版列上的某个按钮,在标签上显示刚刚点击的这个按钮所在行的行号
  • 打赏
  • 举报
回复
我试试
孟大哥出山了,不会有问题了
alicc 2007-02-12
  • 打赏
  • 举报
回复
在页面上定义个全局的js变量
<script>var hanghao=0;</script>

在你的数据列<itemtemplate></itemtemplate>模板中间加入如下的代码

<script>
hanghao++;
document.write('<button name="sss" value="sss" onclick="alert(\''+hanghao+'\');" />');
</script>
孟子E章 2007-02-12
  • 打赏
  • 举报
回复
<script>
function getIt(obj) {
var r,c
o = obj
while(o.tagName != "TD")
o = o.parentNode
if(o.tagName != "TD") return
c = o.cellIndex
while(o.tagName != "TR")
o = o.parentNode
if(o.tagName != "TR") return
r = o.rowIndex
alert(r + " : " +c)
}
</script>

<input type=button onclick="getIt(this)">
  • 打赏
  • 举报
回复
大家支持支持撒
  • 打赏
  • 举报
回复
提前一下
  • 打赏
  • 举报
回复
想要用JAVASCRIPT实现这样的功能
点击GridView里某个按钮,在标签上显示这个按钮所在的行的行号
kaneshiro 2007-02-12
  • 打赏
  • 举报
回复
说具体点,javascript要实现的是什么?
  • 打赏
  • 举报
回复
有没有人会啊
hegang888888888 2007-02-12
  • 打赏
  • 举报
回复
up

62,073

社区成员

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

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

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

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