Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I have this method in the footer of gridview
 
<asp:TemplateField HeaderText="SALARY">
                  <ItemTemplate>
                  <asp:Label ID="sal1" runat="server" Text='<%# Eval("Total") %>'></asp:Label>
                   </ItemTemplate>
<%--            <asp:BoundField DataField="Total" HeaderText="totalprice" />
--%>            <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 ??
 
public int gettotal()
  {
 
      int totalsal = ;
 
      return totalsal;
 
  }
Posted 29-Apr-12 6:17am
Comments
Shahin Khorshidnia at 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?
sara besho at 29-Apr-12 17:30pm
   
what did you mean??
SAKryukov at 29-Apr-12 19:45pm
   
You need to read about binding, to start with...
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
losmac at 29-Apr-12 14:10pm
   
Good links! My 5
Sandeep Mewara at 29-Apr-12 14:21pm
   
Thanks losmac. :)
VJ Reddy at 29-Apr-12 21:04pm
   
Good references. 5!
Sandeep Mewara at 30-Apr-12 0:24am
   
Thanks VJ.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Here is Example to total in footer............
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;
        }
 
    }
 
[EDIT]CODE tags added - LOSMAC[/EDIT]
  Permalink  
v2
Comments
sara besho at 29-Apr-12 17:29pm
   
thank you so much but i didn't get the total from database it doesn't work for me

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 483
1 OriginalGriff 333
2 Maciej Los 305
3 CHill60 220
4 manoj kumar choubey 184
0 OriginalGriff 6,367
1 Sergey Alexandrovich Kryukov 5,296
2 Maciej Los 3,384
3 Peter Leow 3,259
4 DamithSL 2,490


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 29 Apr 2012
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