Search code examples
asp.netgridviewfootersummary

Asp.net Get summary footer in grid view control


I have a grid view control:

 <asp:GridView ID="grdView" runat ="server" AutoGenerateColumns ="false" >                      
     <Columns>                                       
        <asp:BoundField  DataField ="Id" HeaderText ="Agreement ID"/>              
        <asp:BoundField DataField ="Balance" HeaderText ="Balance" />
    </Columns>
</asp:GridView>   

The code behind:

Private Sub form1_Load(sender As Object, e As EventArgs) Handles form1.Load
    Dim agreementManager As AgreementManager = New AgreementManager()
    Dim lstAgr As List(Of Agreement) = agreementManager.GetAll()
    grdView.DataSource = lstAgr
    grdView.DataBind()
End Sub

The output:

GridViewOutput

Then, I want to add a footer with the summary of balance like this:

enter image description here

Any Idea?

Thanks in advance!!


Solution

  • You can achieve this, refer this solution :
    http://www.c-sharpcorner.com/UploadFile/satyapriyanayak/dsfsdf/

    For footer template for each column :

    Dim total As Decimal = dt.AsEnumerable().Sum(Function(row) row.Field(Of Decimal)("Balance"))
    grdView.FooterRow.Cells(0).Text = "Balance"
    grdView.FooterRow.Cells(0).HorizontalAlign = HorizontalAlign.Right
    grdView.FooterRow.Cells(1).Text = total.ToString("Balance")
    

    refer this example : ASP.NET gridview footer template