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_MasterDetail
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Dim myDataSource As DataTable = Nothing
        Dim SqlQuery As String = ""

'        #Region "Populate the Customers"

        'Define SQL query
        SqlQuery = "SELECT CustomerID, CompanyName, ContactName, Address, PostalCode FROM Customers ORDER BY CustomerID"

        'Get DataTable (MS Access Database)
        myDataSource = DataBase.GetDataTableOleDb(SqlQuery, "~/DataGrid/DataBases/Nwind.mdb")

        'Set the data source
        myCustomers.KeyFieldName = "CustomerID"
        myCustomers.DataSource = myDataSource

'        #End Region

'        #Region "Populate the Orders"

        'Define SQL query
        SqlQuery = "SELECT O.OrderID, O.CustomerID, O.OrderDate, O.ShippedDate, S.CompanyName AS Shipper, O.Freight " & _
            "FROM Shippers AS S INNER JOIN Orders AS O ON S.ShipperID = O.ShipVia ORDER BY O.OrderID;"

        'Get DataTable (MS Access Database)
        myDataSource = DataBase.GetDataTableOleDb(SqlQuery, "~/DataGrid/DataBases/Nwind.mdb")

        'Set the data source
        myOrders.KeyFieldName = "OrderID"
        myOrders.DataSource = myDataSource

        'Format the data
        Dim format As System.IFormatProvider = New System.Globalization.CultureInfo("en-US", True)

        myOrders.Columns("OrderDate").FormatProvider = format
        myOrders.Columns("OrderDate").FormatType = GetType(Date)
        myOrders.Columns("OrderDate").FormatString = "MMMM dd, yyyy"

        myOrders.Columns("ShippedDate").FormatProvider = format
        myOrders.Columns("ShippedDate").FormatType = GetType(Date)
        myOrders.Columns("ShippedDate").FormatString = "MMMM dd, yyyy"

        myOrders.Columns("Freight").FormatProvider = format
        myOrders.Columns("Freight").FormatType = GetType(System.Decimal)
        myOrders.Columns("Freight").FormatString = "C"

        'Set the non-existent CustomerID (by default)
        myOrders.RowFilter = "CustomerID='Undefined'"

'        #End Region

    End Sub
End Class