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

📄 search.aspx.cs

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

namespace BookShop.Web
{
	public class Search : Page
	{
		protected NavBar header;
		protected SimplePager products;

		private void InitializeComponent() {}

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

			// Get the search terms from the query string
			string searchKey = WebComponents.CleanString.InputText(Request["keywords"], 100);

			if (searchKey != ""){

				// Create a data cache key
				string cacheKey = "search" + searchKey;

				// Check if the objects are in the cache
				if(Cache[cacheKey] != null){
					products.DataSource = (IList)Cache[cacheKey];
				}else{
					// If that data is not in the cache then use the business logic tier to fetch the data
					Product product = new Product();
					IList productsBySearch = product.GetProductsBySearch(searchKey);
					// Store the results in a cache
					Cache.Add(cacheKey, productsBySearch, null, DateTime.Now.AddHours(12), Cache.NoSlidingExpiration , CacheItemPriority.High, null);
					products.DataSource = productsBySearch;
				}

				// Databind the data to the controls
				products.DataBind();
			}
		}
	}
}

⌨️ 快捷键说明

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