Asp.net获取网格视图控件中的摘要页脚

时间:2017-03-21 17:00:24

标签: asp.net gridview footer summary

我有一个网格视图控件:

 <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>   

背后的代码:

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

输出:

GridViewOutput

然后,我想添加一个包含余额摘要的页脚,如下所示:

enter image description here

任何想法?

提前致谢!!

1 个答案:

答案 0 :(得分:2)

您可以实现此目的,请参阅此解决方案:
http://www.c-sharpcorner.com/UploadFile/satyapriyanayak/dsfsdf/

每列的页脚模板:

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")

参考此示例:ASP.NET gridview footer template