Imports Telerik.Web.UI
Imports System.Data
Imports System.Data.OleDb

Partial Class History
    Inherits System.Web.UI.Page

    Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
        RadGrid1.DataSource = Data
    End Sub

    Protected Sub ScriptManager1_Navigate(ByVal sender As Object, ByVal e As HistoryEventArgs) Handles ScriptManager1.Navigate
        If Not e.State("page") Is Nothing Then
            RadGrid1.CurrentPageIndex = IIf(e.State("page").ToString() <> "", e.State("page"), 0)
            RadGrid1.Rebind()
        End If
    End Sub

    ReadOnly Property Data() As DataTable
        Get
            Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("~/App_Data/Nwind.mdb"))
            Dim adapter As New OleDbDataAdapter()
            adapter.SelectCommand = New OleDbCommand("SELECT * FROM Customers", conn)
            Dim myDataTable As New DataTable()
            conn.Open()
            Try
                adapter.Fill(myDataTable)
            Finally
                conn.Close()
            End Try
            Return myDataTable
        End Get
    End Property

    Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand
        If e.CommandName = RadGrid.PageCommandName Then
            ScriptManager1.AddHistoryPoint("page", e.Item.OwnerTableView.CurrentPageIndex.ToString())
        End If
    End Sub
End Class
