Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java script
How to calculate the sum of column in grid view using java script
Posted 21-Oct-11 3:11am
Comments
vino12345 at 21-Oct-11 9:03am
   
* "grid_list" is my gridview id
 
* "cells[3]" is my column
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

function Read_Data()
    {
        var str=0;
        var Grid_Table = document.getElementById('<%=grid_list.ClientID%>');
        for(var row=1; row<Grid_Table.rows.length; row++)
        {
                        if(document.all)
                            str=str+Number(Grid_Table.rows[row].cells[3].innerText);
 
                        else
                            str=str+Number(Grid_Table.rows[row].cells[3].textContent);
 
        }
        alert(str);
        return false;
    }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Check out this.....
 
function CalculateSum()
  {
    var grid = document.getElementById('<%=gvAttribute.ClientID %>');
    var gridinput = grid.getElementsByTagName('input');
    var sum = 0*1;
 
    for(i = 0; i < gridinput.length; i++)
    {
        var value1 = gridinput[i].value;            
        sum = parseFloat(sum) + parseFloat(value1);
    }
    return parseFloat(sum);
  }
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 21 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100