You can assign a CSS class to your gridview using the CssClass property (I don't remember the exact spelling), and then access its selectors from the jquery css class.
Suppose you assign gridviewclass to this property, and then when you write -
$('table.gridviewclass')
in jquery, you can access the table that is created instead by gridview ASP.NET. Now, to access all the lines, you will write -
$('table.gridviewclass tr')
which will give you all the rows of this table inside the jquery array. To count the number of lines you will write -
var rowcount = $('table.gridviewclass tr').length if(rowcount == 0) { // No rows found, do your stuff } else { // Rows found, do whatever you want to do in this case }
To access the first line you can use the following selector -
$('table.gridviewclass tr:first')
To access the last line you will write -
$('table.gridviewclass tr:last')
etc .. You can find a complete list of jquery selectors here .
Hope this helps.
source share