如何使用javascript访问gridview单元格值 [英] How to access gridview cell value with javascript
本文介绍了如何使用javascript访问gridview单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 javascript 函数,我正在尝试验证 gridview 的输入.我的问题是我无法获得单元格的值.这是我所拥有的:
I have a javascript function that I am trying to validate the inputs of a gridview. My problem is that I cannot get the value of the cell. Here is what I have:
function fcnCheck() {
var grid = document.getElementById("<%= GridViewProducts.ClientID %>");
var cellPivot;
if (grid.rows.length > 0) {
for (i = 1; i < grid.rows.length-1; i++) {
cellPivot = grid.rows[i].cells[0];
cellStatus = grid.rows[i].cells[1];
if (cellPivot == "Yes" and cellStatus == "") {
alert("You must select an answer for all columns if Pivot is yes")
return false;
}
}
}
}
这一行不起作用:cellPivot = grid.rows[i].cells[0];
This line does not work: cellPivot = grid.rows[i].cells[0];
推荐答案
很可能是你想要的(编辑)
Most likely you want (edit)
var theDropdown = grid.rows[i].cells[0].elements[0];
var selIndex = theDropdown.selectedIndex;
cellPivot = theDropdown.options[selIndex].value;
另一种可能更简单或更可靠的方法是以某种方式标记您想要的单元格控件并直接选择它们?
Another possibly easier or more reliable way to do this would be to tag the cells controls you want in some way and select them directly?
这篇关于如何使用javascript访问gridview单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文