Click here to Skip to main content
15,915,611 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All;

Code:
JavaScript
var grid = document.getElementById("<%= grdActivity.ClientID%>");
var inputs = grid.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
     if (inputs[i].name.indexOf("txtGridAmount") > 1) {
        if (inputs[i].value != "") {
           totalAmount = totalAmount + parseFloat(inputs[i].value);
        }
      }


I'm looping my datagrid and adding one Amount column and getting result by using the above codings Perfectly... But I have some problem with this ..

Now I'm getting the correct looped and summed value of the datagrid. But I have given a pageindex to datagrid with 5 rows. So once i'm entering 6th row my script only adding the current page row..

Now i need to loop one column in all the pages of datagrid..

Please guide me.. Thanks in advance .. :-) Waiting for your reply

Thanks & Regards,
Ganesh.
Posted
Updated 13-Dec-12 2:41am
v5

Ideally you should not be doing it in javascript. Why don't you use the gridview footer to display summary information. check this linkt out http://msdn.microsoft.com/en-us/library/bb310552.aspx[^]

Regards
Pawan
 
Share this answer
 
Comments
GANESH KUMAR K 13-Dec-12 23:15pm    
Thank you for your reply to Rai Pawan and Tadit Dash.. Thank you for your both help.. I'm checking those sites.. Let me tell you the result once i get it.. Thank You both again :-)
Problem
The problem is when you have PageIndex defined in DataGrid, then the number of rows per page will be rendered in HTML client-side.

So, you will never get all the rows in the DataGrid.

Solution
You need to loop through the DataSource, from which you get the data.
It may be DataTable or DataSet.
Because at the time of Binding the data, it retrieves all the rows, but when you give PageIndex, it only shows the defined number of rows.

So, catch the DataTable in JavaScript and try to loop through that.
Refer - How to loop through all items in the grid when paging property for grid is set[^] for this concept.

But I found some links where they have done the same way as you did.
Please check what they are doing exactly.
1. Use javascript to loop through all rows of a paging gridview[^].
2. Loop through datagrid in javascript?[^].

Thanks...
 
Share this answer
 
Comments
GANESH KUMAR K 13-Dec-12 23:15pm    
Thank you for your reply to Rai Pawan and Tadit Dash.. Thank you for your both help.. I'm checking those sites.. Let me tell you the result once i get it.. Thank You both again :-)
You are most welcome @GANESH KUMAR K.
Please let me know when you complete this task.

Thanks,
Tadit
GANESH KUMAR K 16-Dec-12 23:43pm    
I'm Sorry to say this..Now I'm trying to loop the grid with TextChanged event for the particular textbox. Anyhow Thanks alot for your response and I'll try this javascript also. And I'm also feeling using javascript is more interactive than Server side Work.. Thank you again for your help... :-)
I also suggested you to do in JavaScript as you are trying in that.
I just gave that link to make you understand the concept. You should try that in JavaScript.
Also given you two links how exactly you should loop DataGrid in JavaScript.

Please accept this answer, if it has helped you in any way.
This will help others to find the answer in one go and you will also be awarded with some points for this action...

Thanks,
Tadit
GANESH KUMAR K 17-Dec-12 3:46am    
Sure :-) Now I'm trying..once i get the answer will do... Thanks...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900