Does anyone know how to count the no of rows in asp:GridView using jQuery. If no rows found then I want to do stuff...
A GridView
is just rendered as a standard HTML table, so just count the number of tr
elements under the GridView:
var totalRows = $("#<%=GridView1.ClientID %> tr").length;
Every GridView produces HTML that is basically a table and that table has an ID (view source of your output page to know what im talking about). You can pass the ID either from .Net to JavaScript by means of myGridView.ClientID
or in ASP.NET 4 make the ClientIdMode="Static"
and thus use the exact same ID you use for the ASP control.
Then in jquery (which is a client-side layer that is completely seperated from the GridView layer), grab that ID and count:
$("#mygridviewid tr").length;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With