📄 items.aspx.cs
字号:
using BookShop.Model;
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Web.Caching;
// PetShop specific imports
using BookShop.BLL;
using BookShop.Web.Controls;
namespace BookShop.Web
{
public class Items : Page
{
protected SimplePager items;
protected NavBar header;
protected System.Web.UI.WebControls.Label productName;
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
protected void PageChanged(object sender, DataGridPageChangedEventArgs e){
items.CurrentPageIndex = e.NewPageIndex;
// Get the productId from the query string
string productId = WebComponents.CleanString.InputText(Request["productId"], 50);
// Array for the data
IList itemsByProduct = null;
// Check if the data exists in the data cache
if(Cache[productId] != null){
itemsByProduct = (IList)Cache[productId];
}else{
// If the data is not in the cache then fetch the data from the business logic tier
Item item = new Item();
itemsByProduct = item.GetItemsByProduct(productId);
// store the output in the data cache with a 12 hour expiry
Cache.Add(productId, itemsByProduct, null, DateTime.Now.AddHours(12), Cache.NoSlidingExpiration , CacheItemPriority.High, null);
}
// Set the control datasource
items.DataSource = itemsByProduct;
// If there is data fetch the product name
if(itemsByProduct.Count > 0)
productName.Text = ((ItemInfo)itemsByProduct[0]).ProductName;
// Bind the data to the the control
items.DataBind();
}
private void Page_Load(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -