当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JavaScript获取GridView选择的行内容

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 JavaScript获取GridView选择的行内容


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 318 ::
收藏到网摘: n/a

一般GridView第一列是多选框CheckBox,负责标记当前行是否被选中,后面可以有文本框TextBox,下拉框DropDownList,标签Lable 这些东西的选取首先就要找出选择的是第几行,如下:
var table = document.getElementById("<%=GridView1.ClientID %>");
var rowIndex = 0 ;
for(var i=1;i<table.rows.length;i++)
{
var input = table.rows[i].cells[0].getElementsByTagName("input")[0].checked;
if (input == true)
{
rowIndex = i;
return rowIndex ;
}
}
取到TextBox中的值
table.rows[rowIndex].cells[3].getElementsByTagName("input")[0].value
取到Lable中的值
table.rows[rowIndex].cells[4].getElementsByTagName("span")[0].innerHTML
后面的.innerHTML可以换成.innerText,不过.innerHTML的浏览器兼容性好些。
(这里要注意了:不管是用.innerHTML还是.innerText都是只把信息显示<span>XXXX</span>之间,而不是像TextBox的标签显示在<input Value="XXXX"></input>中。缺点是:页面一刷新就没有了。)