Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Partial Public Class DataGrid_RowSummary
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
'Define SQL query
Dim SqlQuery As String = "SELECT ProductID, ProductName, UnitPrice, UnitsInStock, UnitsOnOrder FROM Products ORDER BY ProductID"
'Get DataTable (MS Access Database)
Dim myDataSource As DataTable = DataBase.GetDataTableOleDb(SqlQuery, "~/DataGrid/DataBases/Nwind.mdb")
'Set the data source
myDataGrid.KeyFieldName = "ProductID"
myDataGrid.DataSource = myDataSource
myDataGrid.DataBind()
'Compute summary data
Dim UnitPrice_Sum As Decimal = CDec(myDataGrid.Columns("UnitPrice").Sum())
Dim UnitPrice_Min As Decimal = CDec(myDataGrid.Columns("UnitPrice").Minimum())
Dim UnitPrice_Max As Decimal = CDec(myDataGrid.Columns("UnitPrice").Maximum())
Dim UnitsInStock_Sum As Long = CLng(Fix(myDataGrid.Columns("UnitsInStock").Sum()))
Dim UnitsOnOrder_Min As Short = CShort(Fix(myDataGrid.Columns("UnitsOnOrder").Minimum()))
Dim UnitsOnOrder_Max As Short = CShort(Fix(myDataGrid.Columns("UnitsOnOrder").Maximum()))
Dim UnitsOnOrder_Avg As Short = CShort(Fix(myDataGrid.Columns("UnitsOnOrder").Average()))
'Add summary data to the columns
myDataGrid.Columns("ProductID").Summary = "Products: <b>" & _
myDataGrid.Rows.Count.ToString() & "</b>"
myDataGrid.Columns("ProductName").Summary = "Product Categories: <b>Beverages, Condiments, Confections.</b>"
myDataGrid.Columns("UnitPrice").Summary = String.Format("Total: <font color=""#124312""><b>{0:C}</b></font>", UnitPrice_Sum) + String.Format("<br/>Max: <font color=""#000059""><b>{0:C}</b></font>", UnitPrice_Max) + String.Format("<br/>Min: <font color=""#710F0F""><b>{0:C}</b></font>", UnitPrice_Min)
myDataGrid.Columns("UnitsInStock").Summary = "Total: <b>" & _
UnitsInStock_Sum.ToString() & "</b>"
myDataGrid.Columns("UnitsOnOrder").Summary = "Max: <b>" & _
UnitsOnOrder_Max.ToString() & "</b>" & _
"<br/>Min: <b>" & _
UnitsOnOrder_Min.ToString() & "</b>" & _
"<br/>Avg: <b>" & _
UnitsOnOrder_Avg.ToString() & "</b>"
End Sub
End Class
|