Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


I have a Dataset, in that one column is "Count".
In that col records are like this.

Count
10
2
5
1
12


I want Total sum of that column like (10+2+5+1+12).If i add another record means that record also counted automatically.
I want to display that SUM in footer Template of my GridView.

can anyone help me how to do this

Thanks in advance
Posted
Updated 31-Aug-12 6:43am
v3

Here is one way to do it

C#
object objSum;
objSum = YourDataSet.Tables[0].Compute("Sum(Count)", "");
Your_Footer = (int)objSum;


You can refer the below link for more information
DataTable.Compute Method[^]

Here are some threads showing how to display total in gridview footer.
Sum of an Gridview Column should be shown in the last row of Bottom in Gridview[^]
how to calculate total price in the footer of gridview?[^]
How to display GridView Footer[^]
Total Row Footer on DataGridView[^]
How to display GridView Footer[^]
 
Share this answer
 
v3
Comments
[no name] 31-Aug-12 23:45pm    
Your_Footer = (int)objSum;
plz explain this line here "your footer "is ....
and this code written in where...
__TR__ 1-Sep-12 8:49am    
Its just a sample code showing how to use the Compute method and get the footer value. If you are not sure how to use gridview footer refer the threads they explain how to use gridview footer to display total.
Hi,
Try this:
C#
var sum = table.AsEnumerable().Sum(x=>x.Field<int>("Count"));
//Where count is your Column name and table is your table of dataset</int>




--Amit
 
Share this answer
 
v2
Comments
[no name] 31-Aug-12 10:06am    
I'm not using LINQ
C#
DataTable table = YourDataSet.Table[0];
int count = 0;
foreach(DataRow dr in table.Rows)
{
    count+= Convert.ToInt32(dr["Count"]);
}

Your_Footer = count;


Hope it helps.
 
Share this answer
 
Comments
[no name] 1-Sep-12 0:22am    
Your_Footer = count;
plz explain this line
Thanks in advance
Christian Amado 1-Sep-12 0:38am    
Count is the sum of your colum. Your_Footer is any control inside your footer template. =)
[no name] 1-Sep-12 1:00am    
for ex i'm using Label control inside a Footer.
How to write This line.
Your_Footer=count;
[no name] 1-Sep-12 1:14am    
It displays no.of rows in a GridView .But i want Total Of a Specific Col.

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