Click here to Skip to main content
14,733,542 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to calculate the sum of column in grid view using java script
Posted
Comments
vino2012 21-Oct-11 9:03am
   
* "grid_list" is my gridview id

* "cells[3]" is my column

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;
    }
   
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);
  }
   

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