<%@ Page Language="VB" %>
<%@ outputcache duration="10" varybyparam="CategoryID" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

    Sub Page_Load(sender As Object, e As EventArgs)
      Dim strCategoryID As String = Request.Params("CategoryID")
      If Not IsPostBack Then
        BindGrid(strCategoryID)
      End If
    End Sub
    
    Sub BindGrid(strCategoryID)
      Dim strSQL As String = "Select * From Products " & _
        "Where CategoryID=" & strCategoryID
      With DataGrid1
        .DataSource = CreateDataReader(strSQL)
        .DataBind()
      End With
    End Sub
    
    Function CreateDataReader(strSQL As String) As OleDbDataReader
      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 cmd As New OleDbCommand(strSQL, con)
      con.Open()
      Return cmd.ExecuteReader(CommandBehavior.CloseConnection)
    End Function

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False" CellPadding="4" BackColor="White" BorderColor="#336666" BorderWidth="3px" GridLines="Horizontal" BorderStyle="Double">
            <FooterStyle forecolor="#333333" backcolor="White"></FooterStyle>
            <HeaderStyle font-bold="True" forecolor="White" backcolor="#336666"></HeaderStyle>
            <PagerStyle horizontalalign="Center" forecolor="White" backcolor="#336666" mode="NumericPages"></PagerStyle>
            <SelectedItemStyle font-bold="True" forecolor="White" backcolor="#339966"></SelectedItemStyle>
            <ItemStyle forecolor="#333333" backcolor="White"></ItemStyle>
            <Columns>
                <asp:BoundColumn DataField="ProductID" HeaderText="ID"></asp:BoundColumn>
                <asp:BoundColumn DataField="ProductName" HeaderText="商品名"></asp:BoundColumn>
                <asp:BoundColumn DataField="UnitPrice" HeaderText="単価" DataFormatString="{0:c0}"></asp:BoundColumn>
            </Columns>
        </asp:DataGrid>
    </form>
</body>
</html>