我有一个 javascript 函数,我正在尝试验证 gridview 的输入。我的问题是我无法获取单元格的值。这是我所拥有的:
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];
最佳答案
很可能您想要(编辑)
var theDropdown = grid.rows[i].cells[0].elements[0];
var selIndex = theDropdown.selectedIndex;
cellPivot = theDropdown.options[selIndex].value;
另一种可能更简单或更可靠的方法是以某种方式标记您想要的单元格控件并直接选择它们?
关于javascript - 如何使用javascript访问gridview单元格值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4097736/