12,352,294 members (55,569 online)
Rate this:
See more:
Dear Friends,

Have a Good Day !!

How to do Total sum in Gridview Footer in Asp.net C# ?
=======================================

I have a Gridview which has the fields like UserName, Login Time , Logout Time , Duration. I need to do total duration of hours in footer

These are my Fields in my Gridview

Posted 26-Aug-12 20:11pm

Rate this:

## Solution 2

```var result = from p in st.prices select new {
p.id,
p.Name,
p.price1 };
GridView1.DataSource = result;
GridView1.DataBind();
double sum=0;
foreach(var item in result){

sum += Convert.ToDouble(item.price1);
}
Label lblsum = (Label)GridView1.FooterRow.FindControl("Lbltotal");
lblsum.Text = sum.ToString();```
v2
karthik mahalingam01 30-Dec-13 3:55am

good try..
karthik mahalingam01 30-Dec-13 3:57am

always put your code in code block...
Rate this:

v2
Rate this:

## Solution 1

__TR__ 27-Aug-12 2:25am

My 5!
karthik mahalingam01 30-Dec-13 3:57am

Mohamed Mitwalli 27-Aug-12 2:28am

Thank you TR :)
Mohamed Mitwalli 30-Dec-13 4:22am

Thanks Karthik :)
Rate this:

## Solution 3

```decimal a = 0;
Int32 y = GridView1.Items.Count;
for (Int32 i = 0; i < y ; i++)
{

a = a + Convert.ToDecimal(((Label)GridView1.Items[i].FindControl("lbl_subtoprice")).Text.ToString());

}

lbl_grandtotal.Text = Convert.ToString(a);
```
```lbl_subtopricel id of your durations values
and
lbl_grandtotal is id of label in footer```
karthik mahalingam01 30-Dec-13 3:56am

good try.
Omprakash Kukana 30-Dec-13 3:57am

thanx

Top Experts
Last 24hrsThis month
 OriginalGriff 564 Sergey Alexandrovich Kryukov 301 Maciej Los 250 Dave Kreskowiak 150 Karthik Bangalore 149
 OriginalGriff 9,219 Sergey Alexandrovich Kryukov 6,299 Dave Kreskowiak 3,044 ppolymorphe 2,256 Karthik Bangalore 2,251