Home > Web Front-end > JS Tutorial > body text

Two ways to get row data in GridView using js Share_javascript skills

WBOY
Release: 2016-05-16 17:28:58
Original
1383 people have browsed it

The first method:

Copy code The code is as follows:

function submitData() {
var tb = document.getElementById(IDArray[0]); //Get the ID of the server control GridView
if (tb)
{
var rows = tb.rows;
for (var i = 1; i < rows.length; i ) {
var id = rows[i].cells[1].innerText;
var name = rows[i].cells[2].innerHTML;
var oDropDownList = rows[i].cells[3].childNodes[0];
var oText = oDropDownList.options[oDropDownList.selectedIndex].text; //Get the selected text in the drop-down list in GridView
var oValue = oDropDownList.options[oDropDownList.selectedIndex].value;; //Get the value selected in the drop-down list in the GridView
}
}
}

Second Method:
Copy code The code is as follows:

function submitData() {
var tb = document.getElementById(IDArray[0]);
if (tb.hasChildNodes) {
if (tb.childNodes[0] != null) {
var rowCount = tb.childNodes[0] .childNodes.length;
for (var i = 1; i < rowCount; i ) {
var child = tb.childNodes[0].childNodes[i];
var id = rowCount[i ].cells[1].innerHTML;
var name = child.childNodes[1].innerHTML;
var oDropDownList = child.childNodes[2].childNodes[0];
var oText = oDropDownList. options[oDropDownList.selectedIndex].text;
var oValue = oDropDownList.options[oDropDownList.selectedIndex].value
}
}
} >
Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template