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

📄 category.aspx.cs

📁 ASP.net网站开发四“酷”全书:新闻、论坛、电子商城、博客_源码
💻 CS
字号:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;
using System.Web.Caching;

// PetShop specific imports
using BookShop.BLL;
using BookShop.Web.Controls;

namespace BookShop.Web {
	public class Category : Page {
		protected NavBar header;
		protected SimplePager products;
		protected System.Web.UI.WebControls.Label lblPage;
		protected System.Web.UI.HtmlControls.HtmlForm form;

		private void InitializeComponent() {}

		protected void PageChanged(object sender, DataGridPageChangedEventArgs e) {
			
			products.CurrentPageIndex = e.NewPageIndex;

			// Get the category from the query string
			// string categoryKey = Request["categoryId"];
			string categoryKey = WebComponents.CleanString.InputText(Request["categoryId"], 50);

			// Check to see if the contents are in the Data Cache
			if(Cache[categoryKey] != null){
				// If the data is already cached, then used the cached copy
				products.DataSource = (IList)Cache[categoryKey];
			}else{
				// If the data is not cached, then create a new products object and request the data
				Product product = new Product();
				IList productsByCategory = product.GetProductsByCategory(categoryKey);
				// Store the results of the call in the Cache and set the time out to 12 hours
				Cache.Add(categoryKey, productsByCategory, null, DateTime.Now.AddHours(12), Cache.NoSlidingExpiration , CacheItemPriority.High, null);
				products.DataSource = productsByCategory;
			}

			// Bind the data to the control
			products.DataBind();
			// Set the label to be the query parameter
			lblPage.Text = categoryKey;
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -