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.
SHARE

Nothing shocks me, I'm a Software Engineer. And I am not young enough to know everything. I live in World Wide Web and from there take care of this website. This website communicates about my work, learning and experience. I believe life is short, and it is for loving, sharing, learning and connecting. So lets connect..