简体   繁体   中英

Loop through gridview rows on client-side javascript

I have a gridview with a template field of check boxes.

I have my rows color coded in BLUE color in the gridview based on a database value on page load.

Now I want a button on the page to loop through the gridview and select the the checkbox for the rows that are in BLUE Color without a post back.

any help would be appreciated.

thanks.

Loop through gridview rows on client-side javascript

var GridviewRows = $("#<%=gvbooksdetails.ClientID%> tr").length;
var rowlenght = GridviewRows - 1;
for (var i = 0; i < rowlenght; i++)
    {                                                  
    var Aname = document.getElementById("MainContent_gvbooksdetails_lblgvauthorname_" +[i]+"").innerHTML;
    var Bname = document.getElementById("MainContent_gvbooksdetails_lblgvbookname_" +[i]+ "").innerHTML;
    var BType = document.getElementById("MainContent_gvbooksdetails_lblgvbooktype_" +[i]+ "").innerHTML;
    var Pubilication = document.getElementById("MainContent_gvbooksdetails_lblgvPublisher_" + [i] + "").innerHTML;
    var Bid = document.getElementById("MainContent_gvbooksdetails_hiddenid_"+[i]+"").value;
    }

Instead of foreach we can use this method.

$('#mygrid tr.blueClass input[type="checkbox"]').each(
     function() { 
         this.checked = true;
 });

Assuming mygrid is the name of your gridview, and each blue row has a class called blueClass

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM