⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cachestore.aspx

📁 asp.net技术内幕的书配源码
💻 ASPX
字号:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat=server>

DataSet dstStore;

void Page_Load(Object sender , EventArgs e) 
{
	SqlConnection conNorthwind;
	SqlDataAdapter dadNorthwind;
	 
	dstStore = (DataSet)Cache["Store"];
	 
	if ( dstStore == null ) {
		dstStore = new DataSet();
		conNorthwind = new SqlConnection( @"Server=localhost;Integrated Security=SSPI;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();
		//DataSet dstStore = (DataSet)Cache["Store"];
	}
	if (! IsPostBack ) {
		dgrdCategories.DataSource = dstStore;
		dgrdCategories.DataMember = "Categories";
		dgrdCategories.DataBind();
	}
}

void dgrdCategories_ItemCommand( object s, DataListCommandEventArgs e ) {
	DataView dvwProducts;
	int intCategoryID;

	// Select the Chosen Category
	dgrdCategories.SelectedIndex = e.Item.ItemIndex;

	// get CategoryID from DataKeys Collection
	intCategoryID = System.Convert.ToInt32(dgrdCategories.DataKeys[e.Item.ItemIndex]);

	// Filter the Products
	dvwProducts = dstStore.Tables["Products"].DefaultView;
	dvwProducts.RowFilter = "CategoryID=" + intCategoryID;
	dgrdProducts.DataSource = dvwProducts;
	dgrdProducts.DataBind();
}
</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='<%# ((DataRowView)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 + -