Imports System Imports Northwind45.BusinessObject Imports System.Web.UI.WebControls Imports System.Runtime.InteropServices Namespace Northwind45 Partial Public Class GridViewTotals_Products Inherits System.Web.UI.Page Private _totalUnitPrice As Decimal = 0 Protected Sub GridView1_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Functions.GridViewRowDataBound(sender, e, 1) If e.Row.RowType = DataControlRowType.Footer Then ' display totals in the footer Dim objProducts As Products = Products.SelectTotals() e.Row.Cells(5).Text = "Subtotal: " & _totalUnitPrice.ToString("c") & "<br/>Grand Total: " & objProducts.UnitPriceTotal.ToString("c") End If End Sub Protected Sub GridView1_RowCreated(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Functions.GridViewRowCreated(sender, e, 0) End Sub Public Function GetGridData(maximumRows As Integer, startRowIndex As Integer, <Out()> ByRef totalRowCount As Integer, sortByExpression As String) As ProductsCollection Dim objProductsCol As ProductsCollection = Products.SelectSkipAndTake(maximumRows, startRowIndex, totalRowCount, sortByExpression) LblNumberOfRecords.Text = totalRowCount.ToString("n0") For Each objProducts As Products In objProductsCol If objProducts.UnitPrice.HasValue Then _totalUnitPrice += objProducts.UnitPrice.Value End If Next Return objProductsCol End Function End Class End Namespace