Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8801039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:44:20+00:00 2026-06-14T00:44:20+00:00

I have a gridview with total at the footer. My paging allows only 25

  • 0

I have a gridview with total at the footer. My paging allows only 25 records for each page. So when there are multiple pages there should be running total and the grand total. Could me anyone help me with the code. below are the code for the total for a column.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowSorting="true" ShowFooter="True" OnPageIndexChanging="GridView1_PageIndexChanging" OnDataBound="GridView1_DataBound" OnRowDataBound="GridView1_RowDataBound" OnRowCreated="GridView1_RowCreated">
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="30px"                                                                                                          HeaderStyle-VerticalAlign="Top" ItemStyle-Wrap="True">
<ItemTemplate>
<asp:Label ID="lblcriteria" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"CRITERIA_N") %>' />
</ItemTemplate></asp:TemplateField>
<asp:TemplateField HeaderText="Period" SortExpression="PERIOD_N" ItemStyle-HorizontalAlign="Center"
 HeaderStyle-VerticalAlign="Top" ItemStyle-Wrap="True">
<ItemTemplate>
<asp:Label ID="lblPERIOD_N" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"PERIOD_N") %>' /></ItemTemplate></asp:TemplateField>
<asp:TemplateField HeaderText="Receipts" SortExpression="CHECK_AMT_A_USD" ItemStyle-HorizontalAlign="Center"
HeaderStyle-VerticalAlign="Top" HeaderStyle-Width="70px">
<ItemTemplate>
<asp:Label ID="lblReceipt" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"CHECK_AMT_A_USD") %>' /></ItemTemplate>
<FooterTemplate>
<asp:Label ID="lbltotReceipt" runat="server"></asp:Label>
<asp:Label ID="lblgrangtot" runat="server"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
</column>

aspx.cs

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    GridView grid = sender as GridView;
    DataRowView tableData = e.Row.DataItem as DataRowView;
    DataTable dt = Session["List"] as DataTable;       

    if (e.Row.RowType == DataControlRowType.Header)
    {
        totreceipt = 0; 
    }
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Label lblReceipt = (Label)e.Row.FindControl("lblReceipt");
        totreceipt += Convert.ToDecimal(tableData["CHECK_AMT_A_USD"]);
    }
    if (e.Row.RowType == DataControlRowType.Footer)
    {

        Label lbltotReceipt = (Label)e.Row.FindControl("lbltotReceipt");
        lbltotReceipt.Text = string.Format("{0:N2}", totreceipt);
        e.Row.Cells[0].Text = "Total:";
    }

}

I couldn’t go through the sample ones. Those are pretty confusing. So Kindly help with the coding.

UPDATE:

Here is my SP..

CREATE procedure [dbo].[SP_AVG_DAYS]      

@Cont_C char(1),      
@Month_dd varchar(10),        
@MonYr_S VARCHAR(12),        
@2_Div_Code VARCHAR(2)       

As                  

DECLARE @SelectText varChar(2000)                         
DECLARE @Table varchar(30)      

IF @2_Div_Code <> ''    
BEGIN    
 IF @MonYr_S='Div_Reg'    
 BEGIN    
  SET @Table='VW_BPDP_DIV_REG'    
 END    
 IF @MonYr_S='Div_Area'    
 BEGIN     
  SET @Table='VW_BPDP_DIV_AREA'    
 END    
 IF @MonYr_S='Div_Loc'    
 BEGIN     
  SET @Table='VW_BPDP_DIV_LOC'    
 END 
 END


SET @SelectText='SELECT CRITERIA_N,HEADER_N,PERIOD_N,CHECK_RECEIPT, BP_DAYS 
FROM ' + @Table + '       
WHERE  CONT_C = ''' + @Cont_C + ''' AND DIV_C = ''' + @2_Div_Code + ''' '     

EXECUTE(@SelectText)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:44:21+00:00Added an answer on June 14, 2026 at 12:44 am

    the running total is ok from your code..
    the grand total you can compute it by saving the running total from each page into viewState or Session.
    Or do you want to show the grand total for all entries from the beginning?

    I assume you do not need the GrandTotal for all tables, so I would suggest to have another varchar variable : @SelectCriteria which you set in the places you would like to have a grand total

    CREATE procedure [dbo].[SP_AVG_DAYS]   
    @Cont_C char(1),      
    @Month_dd varchar(10),        
    @MonYr_S VARCHAR(12),        
    @2_Div_Code VARCHAR(2),        
    @2_Reg_Code VARCHAR(3),        
    @2_Area_Code VARCHAR(3),        
    @2_CR_Code VARCHAR(3)       
    
    As                  
    
    DECLARE @SelectText varChar(2000)                         
    DECLARE @SelectCriteria varChar(100)    
    DECLARE @Table varchar(30)      
    
    IF @2_Div_Code <> ''    
    BEGIN    
    IF @MonYr_S='Div_Reg'    
     BEGIN    
       SET @SelectCriteria =', Sum(_columnWithValues) as GrandTotal'
       SET @Table='IA_VPAYMENTS_BPDP_DIV_REG'    
     END    
    IF @MonYr_S='Div_Area'    
      BEGIN     
    SET @Table='IA_VPAYMENTS_BPDP_DIV_AREA'    
    
    END    
     IF @MonYr_S='Div_Loc'    
     BEGIN     
      SET @Table='IA_VPAYMENTS_BPDP_DIV_LOC'    
     END 
     END
    
    
    SET @SelectText='SELECT CRITERIA_N,HEADER_N,PERIOD_N,CHECK_RECEIPT, BP_DAYS' + @SelectCriteria + ' FROM ' + @Table + 'WHERE  CONT_C = ''' + @Cont_C + ''' AND DIV_C = ''' + @2_Div_Code + ''' '     
    EXECUTE(@SelectText)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to get the total number of records in the footer of gridview. i
I have a gridview with a footer and I display the total of the
I have one GridView which has multiple columns. Here I just mentioned only the
Situation: I have several Gridviews on one page, and each Gridview has a dynamically
I have a gridview which displays the records in the below form: Date Total
I have GridView on my page: <%@ Page Language=C# AutoEventWireup=true CodeFile=Default.aspx.cs Inherits=_Default %> <!DOCTYPE
I have a gridview and sqldatasource. I'm trying to insert new records in database
Problem: I've coded a GridView in the markup in a page. I have coded
I have GridView and this grid has setup paging, but this paging not show
I have GridView that allows select. It takes data from EntityDataSource . How do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.