How to loop through all grid view rows using jQuery

In this post, I will show you that how can you loop through individual rows of ASP.NET GridView using jQuery. You might be knowing that GridView is rendered as table > th > tr > td format. The columns names are placed in th tag and all the data goes into various td tags. So when you want to loop through all the rows then, just find the rows which have td and are part of ID of your GridView.

Also read GridView Tips and Tricks using jQuery

See below jQuery Code. In this code, the ID of GridView is "gdRows".

$(document).ready(function() {
  $("#<%=gdRows.ClientID%> tr:has(td)").each(function() {
       alert($(this).html());
  });
});

If you want to loop through all the rows including th as well, then use below code.

$(document).ready(function() {
  $("#<%=gdRows.ClientID%> tr").each(function() {
       alert($(this).html());
  });
});

And lastly, if you want to access only th row then

$(document).ready(function() {
  $("#<%=gdRows.ClientID%> th").each(function() {
       alert($(this).html());
  });
});

Also read GridView Tips and Tricks using jQuery

Feel free to contact me for any help related to jQuery, I will gladly help you.



Responsive Menu
Add more content here...