📄 cachestore.aspx
字号:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<Script Runat="Server">
Dim dstStore As DataSet
Sub Page_Load
Dim conNorthwind As SqlConnection
Dim dadNorthwind As SqlDataAdapter
dstStore = Cache( "Store" )
If dstStore Is Nothing Then
dstStore = New DataSet()
conNorthwind = New SqlConnection( "Server=localhost;UID=sa;PWD=secret;Database=Northwind" )
dadNorthwind = New SqlDataAdapter( "Select CategoryID, CategoryName From Categories", conNorthwind )
conNorthwind.Open()
dadNorthwind.Fill( dstStore, "Categories" )
dadNorthwind.SelectCommand = New SqlCommand( "Select * From Products", conNorthwind )
dadNorthwind.Fill( dstStore, "Products" )
conNorthwind.Close()
Cache( "Store" ) = dstStore
End If
If Not IsPostBack Then
dgrdCategories.DataSource = dstStore
dgrdCategories.DataMember = "Categories"
dgrdCategories.DataBind()
End If
End Sub
Sub dgrdCategories_ItemCommand( s As Object, e As DataListCommandEventArgs )
Dim dvwProducts As DataView
Dim intCategoryID
' Select the Chosen Category
dgrdCategories.SelectedIndex = e.Item.ItemIndex
' Get CategoryID from DataKeys Collection
intCategoryID = dgrdCategories.DataKeys( e.Item.ItemIndex )
' Filter the Products
dvwProducts = dstStore.Tables( "Products" ).DefaultView()
dvwProducts.RowFilter = "CategoryID=" & intCategoryID
dgrdProducts.DataSource = dvwProducts
dgrdProducts.DataBind()
End Sub
</Script>
<html>
<head><title>CacheStore.aspx</title></head>
<body>
<form Runat="Server">
<table width="100%">
<tr><td valign="top" width="200">
<asp:DataList
ID="dgrdCategories"
OnItemCommand="dgrdCategories_ItemCommand"
SelectedItemStyle-BackColor="Yellow"
DataKeyField="CategoryID"
Runat="Server">
<ItemTemplate>
<asp:LinkButton
Text='<%# Container.DataItem( "CategoryName" ) %>'
Runat="Server" />
</ItemTemplate>
</asp:DataList>
</td><td valign="top">
<asp:DataGrid
ID="dgrdProducts"
Runat="Server" />
</td></tr>
</table>
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -