Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to count number of rows in gridview in javascript?

As the question says, i wish to count the number of rows in gridview via JS. I am doing the way it is done here but that is not coming up correctly.

I have also tried different ways as:

 1. var rowscount = document.getElementByID('<%=Gridview1.ClientID%>').rows.length; 
 2. var rowscount = document.getElementByID("<%=Gridview1.ClientID%>").rows.length; 
 3. var rowscount = document.getElementByID('<%#Gridview1.ClientID%>').rows.length;
 4. var rowscount = document.getElementByID("<%#Gridview1.ClientID%>").rows.length;    
 5. var rowscount = document.getElementByID("Gridview1.ClientID").rows.length;
 6. var rowscount = document.getElementByID("Gridview1").rows.length;  

UPDATE : Forgot to Mention: My gridview is inside updatepanel. Would that make any difference? What is the right statement?

like image 352
xorpower Avatar asked Aug 25 '11 13:08

xorpower


1 Answers

If you want to get the number of rows from the server one way would be to use:

var rowsCount = <%=GridView1.Rows.Count %>

It is also possible to send the data to JavaScript from codebehind.

like image 187
Răzvan Flavius Panda Avatar answered Sep 20 '22 23:09

Răzvan Flavius Panda