Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 28, 2010 09:21 AM by samipKS
Member
67 Points
113 Posts
Jan 06, 2008 09:04 PM|LINK
Participant
807 Points
202 Posts
Jan 06, 2008 09:21 PM|LINK
Try taking a look here.
83 Points
25 Posts
Jan 06, 2008 10:11 PM|LINK
Hi its easy,
When a gridview is parsed and sended to the client browser it is parsed to a table so you just have to find that element and count the rows and subtract the header, footer or pager ..
All-Star
126896 Points
17922 Posts
MVP
Jan 07, 2008 09:03 AM|LINK
One way to do that is store the value of the gridview row counts in aspnet HiddenField after binding your gridView like
DataTable dt = //configure datasource here
GridView1.DataSource = dt;
GridView1.DataBind();
HiddenField1.value = GridView1.Rows.Count.ToString();
Then with the value of the HiddenField you can access it in your JS code
var count = document.getElementById('HiddenField1');
alert(count.value);
Hope my suggestion helps
1120 Points
225 Posts
Jan 07, 2008 10:55 AM|LINK
<
GridView1.DataSource = tbl GridView1.DataBind() htmlHidden.value = GridView1.Rows.Count.ToString() 'Binding the GridView 3) To call this value in Javascript, on click of any button to verify the value. alert(document.forms[0].htmlHidden.value);
Jan 07, 2008 07:37 PM|LINK
Im trying the hidden field, but cant get the javascript to work. I have added a hidden field called hidrownumber, and made it "runatserver".
what is wrong with this javascript that i have put in a buttons onclick event?
if(document.getElementByID('<% =hidrownumber.clientID %>').value="0") {alert('error');return false;}
Jan 07, 2008 08:10 PM|LINK
DanMikkelsen if(document.getElementByID('<% =hidrownumber.clientID %>').value="0") {alert('error');return false;}
getElementById
if (document.getElementById('<%=hdnfield.clientID%>').value =="0") { alert ("error"); }
Jan 07, 2008 08:35 PM|LINK
Thanks for the help. Now it works like it is supposed to!
2 Points
4 Posts
Jan 28, 2010 09:21 AM|LINK
Thanks, it helped me.
DanMikkelsen
Member
67 Points
113 Posts
Getting gridview rowcount through javascript
Jan 06, 2008 09:04 PM|LINK
dcwhisen
Participant
807 Points
202 Posts
Re: Getting gridview rowcount through javascript
Jan 06, 2008 09:21 PM|LINK
Try taking a look here.
http://www.netomatix.com/development/GridViewClientSideAccess.aspxjpe.pinho
Member
83 Points
25 Posts
Re: Getting gridview rowcount through javascript
Jan 06, 2008 10:11 PM|LINK
Hi its easy,
When a gridview is parsed and sended to the client browser it is parsed to a table so you just have to find that
element and count the rows and subtract the header, footer or pager ..
vinz
All-Star
126896 Points
17922 Posts
MVP
Re: Getting gridview rowcount through javascript
Jan 07, 2008 09:03 AM|LINK
One way to do that is store the value of the gridview row counts in aspnet HiddenField after binding your gridView like
DataTable dt = //configure datasource here
GridView1.DataSource = dt;
GridView1.DataBind();
HiddenField1.value = GridView1.Rows.Count.ToString();
Then with the value of the HiddenField you can access it in your JS code
var count = document.getElementById('HiddenField1');
alert(count.value);
Hope my suggestion helps
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
raheel.hussa...
Participant
1120 Points
225 Posts
Re: Getting gridview rowcount through javascript
Jan 07, 2008 10:55 AM|LINK
<
input type="hidden" id="htmlHidden" runat="server" /> 2) Everytime, when Binding the Gridview, put a value in this Hidden VariableGridView1.DataSource = tbl
Regards -GridView1.DataBind()
htmlHidden.value = GridView1.Rows.Count.ToString() 'Binding the GridView
3) To call this value in Javascript, on click of any button to verify the value.
alert(document.forms[0].htmlHidden.value);
--------------------------------
Blog:
http://www.dnfug.com/web/blogs/raheel/
URL: http://www.raheelhussain.com/
--------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
DanMikkelsen
Member
67 Points
113 Posts
Re: Getting gridview rowcount through javascript
Jan 07, 2008 07:37 PM|LINK
Im trying the hidden field, but cant get the javascript to work. I have added a hidden field called hidrownumber, and made it "runatserver".
what is wrong with this javascript that i have put in a buttons onclick event?
if(document.getElementByID('<% =hidrownumber.clientID %>').value="0") {alert('error');return false;}
raheel.hussa...
Participant
1120 Points
225 Posts
Re: Getting gridview rowcount through javascript
Jan 07, 2008 08:10 PM|LINK
Please make sure that it is not
.value="0" with single equals sign, it should be == for comparision
Secondly
you function for Javascript getElementByID is wrong as the right function is
getElementById
with small d in the last, remember it is always case sensitiveso try the following code
if (document.getElementById('<%=hdnfield.clientID%>').value =="0") { alert ("error"); }Regards - raheel
--------------------------------
Blog:
http://www.dnfug.com/web/blogs/raheel/
URL: http://www.raheelhussain.com/
--------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
DanMikkelsen
Member
67 Points
113 Posts
Re: Getting gridview rowcount through javascript
Jan 07, 2008 08:35 PM|LINK
Thanks for the help. Now it works like it is supposed to!
samipKS
Member
2 Points
4 Posts
Re: Getting gridview rowcount through javascript
Jan 28, 2010 09:21 AM|LINK
Thanks, it helped me.