15,851,514 members
See more: , +
I have this method in the footer of gridview

XML
```<asp:TemplateField HeaderText="SALARY">
<ItemTemplate>
<asp:Label ID="sal1" runat="server" Text='<%# Eval("Total") %>'></asp:Label>
</ItemTemplate>
--%>            <FooterTemplate>

<%# gettotal()%>

</FooterTemplate>
</asp:TemplateField>```

now inside this method I want to calculate the total how to get the values from all cells which in the total column in gridview ??

C#
```public int gettotal()
{

int totalsal = ;

}```
Posted
Shahin Khorshidnia 29-Apr-12 12:38pm
Is the GridView bound to a Collection or something else? Is yes why don't you calculate the total from the Collection?
Sarah Mohammed77 29-Apr-12 17:30pm
what did you mean??
Sergey Alexandrovich Kryukov 29-Apr-12 19:45pm
--SA

## Solution 1

Maciej Los 29-Apr-12 14:10pm
Sandeep Mewara 29-Apr-12 14:21pm
Thanks losmac. :)
VJ Reddy 29-Apr-12 21:04pm
Good references. 5!
Sandeep Mewara 30-Apr-12 0:24am
Thanks VJ.

## Solution 2

Here is Example to total in footer............
C#
```protected void grdGuestTotal_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType.Equals(DataControlRowType.Footer))
{
//String NetSubTotal = string.Empty;
// String SubTotal = string.Empty;
Label NetSubTotal = ((Label)e.Row.FindControl("lblNetSubTotal"));
Label FinalTotal = ((Label)e.Row.FindControl("lblTotal"));
NetSubTotal.Text = Total.ToString();
FinalTotal.Text = EndTotal.ToString();// (Convert.ToDouble(NetSubTotal.Text) + Convert.ToDouble(SubTotal.Text)).ToString();
}
if (e.Row.RowType.Equals(DataControlRowType.DataRow))
{
//String NetSubTotal = string.Empty;
// String SubTotal = string.Empty;
Label SubTotal = ((Label)e.Row.FindControl("lblSubTotal"));
Label NetTotal = ((Label)e.Row.FindControl("lblNetTotal"));
double value = Convert.ToDouble(SubTotal.Text);
Total += value;
double amount = Convert.ToDouble(NetTotal.Text);

EndTotal += amount;
}

}```

v2