Two Methods for js to obtain row data in the GridView _ javascript tips-js tutorial

Source: Internet
Author: User
Tags rowcount
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
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.