using System; using Northwind45.BusinessObject; using System.Web.UI.WebControls; namespace Northwind45 { public partial class GridViewTotals_Products : System.Web.UI.Page { private decimal _totalUnitPrice = 0; protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) { Functions.GridViewRowDataBound(sender, e, 1); if (e.Row.RowType == DataControlRowType.Footer) { // display totals in the footer Products objProducts = Products.SelectTotals(); e.Row.Cells[5].Text = "Subtotal: " + _totalUnitPrice.ToString("c") + "<br/>Grand Total: " + objProducts.UnitPriceTotal.ToString("c"); } } protected void GridView1_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) { Functions.GridViewRowCreated(sender, e, 0); } public ProductsCollection GetGridData(int maximumRows, int startRowIndex, out int totalRowCount, string sortByExpression) { ProductsCollection objProductsCol = Products.SelectSkipAndTake(maximumRows, startRowIndex, out totalRowCount, sortByExpression); LblNumberOfRecords.Text = totalRowCount.ToString("n0"); foreach (Products objProducts in objProductsCol) { if (objProducts.UnitPrice.HasValue) _totalUnitPrice += objProducts.UnitPrice.Value; } return objProductsCol; } } }