This article introduces how js obtains the row data in the GridView. If you need it, refer to the first method:
The Code is as follows:
Function submitData (){
Var tb = document. getElementById (IDArray [0]); // obtain 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; // obtain the text from the drop-down list in the GridView.
Var oValue = oDropDownList. options [oDropDownList. selectedIndex]. value; // obtain the value from the drop-down list in the GridView.
}
}
}
Method 2:
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
}
}
}