<%@ Page Language="VB" EnableViewState="False" Trace="False" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

    Private mdtProducts As DataTable
    
    Sub Page_Load(sender As Object, e As EventArgs)
      BindGrid()
    End Sub
    
    Sub BindGrid()
      mdtProducts = Cache("Products")
      If mdtProducts Is Nothing Then
        mdtProducts = CreateDataTable()
      End If
      DataGrid1.DataSource = mdtProducts
      DataGrid1.DataBind()
    End Sub
    
    Function CreateDataTable() As DataTable
      Dim strSQL As String = "Select * From Customers"
      Dim strConnectionString As String = _
        String.Format("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source={0}", _
          Server.MapPath("webdb/Nwind.mdb"))
      Dim con As New OleDbConnection(strConnectionString)
      Dim da As New OleDbDataAdapter(strSQL, con)
      Dim dt As New DataTable()
    
      da.Fill(dt)
      Cache("Products") = dt
      Return(dt)
    End Function
    
    Sub DataGrid1_PageIndexChanged(sender As Object, e As DataGridPageChangedEventArgs)
      Trace.Warn("PageIndexChanged")
      DataGrid1.CurrentPageIndex = e.NewPageIndex
      BindGrid()
    End Sub

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <h3>ビューステート無効（その2）</h3>
        <asp:DataGrid id="DataGrid1" runat="server" OnPageIndexChanged="DataGrid1_PageIndexChanged" AllowPaging="True" AutoGenerateColumns="False" CellPadding="4" BackColor="White" BorderWidth="1px" BorderStyle="None" BorderColor="#3366CC">
            <FooterStyle forecolor="#003399" backcolor="#99CCCC"></FooterStyle>
            <SelectedItemStyle font-bold="True" forecolor="#CCFF99" backcolor="#009999"></SelectedItemStyle>
            <ItemStyle forecolor="#003399" backcolor="White"></ItemStyle>
            <HeaderStyle font-bold="True" horizontalalign="Center" forecolor="#CCCCFF" backcolor="#003399"></HeaderStyle>
            <Columns>
                <asp:BoundColumn DataField="CustomerID" HeaderText="ID">
                    <HeaderStyle width="3em"></HeaderStyle>
                    <ItemStyle horizontalalign="Right"></ItemStyle>
                </asp:BoundColumn>
                <asp:BoundColumn DataField="CompanyName" HeaderText="得意先">
                    <HeaderStyle width="15em"></HeaderStyle>
                </asp:BoundColumn>
            </Columns>
            <PagerStyle horizontalalign="Right" forecolor="#003399" position="Top" backcolor="#99CCCC" mode="NumericPages"></PagerStyle>
        </asp:DataGrid>
    </form>
</body>
</html>