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

📄 product.aspx.cs

📁 PetShop实现的是一个网上购物的系统功能
💻 CS
字号:
using System;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using PetShop.Components;

namespace PetShop.Web {

	public partial class Product : System.Web.UI.Page {
		protected System.Web.UI.WebControls.ImageButton btnPrevious;
		protected System.Web.UI.WebControls.ImageButton btnNext;

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
		}
		#endregion

		// constants
		const int pageSize = 4;
		const int numSeachResults = 0;

		// page variables
		private int currentPage = 0;
		private int pageCount = 0; 
		private int numResults;

		protected void Page_Load(object sender, System.EventArgs e) {
			if (Page.IsPostBack == false) {				
				// First time here we want to fetch the first page. All of the
				// other page requests will be handled through the page 
				// navigation button event handlers.
				currentPage = 1;
				BindPagedData();
			}
		}

		private void BindPagedData() {
			string prodid = Request.QueryString["product_id"];
			string prodName = Request.QueryString["name"];

			// pull the values off the query string
			if (Request.QueryString["requestedPage"] != null) {
				currentPage = System.Int32.Parse(Request.QueryString["requestedPage"]);
				pageCount = System.Int32.Parse(Request.QueryString["pageCount"]);
			}
			else
				currentPage = 1;
		
			// get page of data and bind to list			
			Components.Item item = new Components.Item();
			ItemResults[] results = item.GetList(prodid, currentPage, pageSize, ref numResults);
			
			list.DataSource = results;
			list.DataBind();

			// if this is the first time, calculate the total number of pages
			if (!Page.IsPostBack)
				pageCount = (int)System.Math.Ceiling((double)numResults / pageSize);
			
			// hide or show navigation buttons
			if (pageCount > 1) {
				// there are multiple pages
				lnkPrevious.Visible = currentPage > 1;
				lnkNext.Visible = currentPage < pageCount;
				lnkPrevious.NavigateUrl = "Product.aspx?name=" + prodName + "&product_id=" + prodid + "&requestedPage=" + (currentPage - 1) + "&pageCount=" + pageCount;
				lnkNext.NavigateUrl = "Product.aspx?name=" + prodName + "&product_id=" + prodid + "&requestedPage=" + (currentPage + 1) + "&pageCount=" + pageCount;
			}
			else {
				// there is only one page, hide both buttons
				lnkPrevious.Visible = lnkNext.Visible = false;
				lnkPrevious.NavigateUrl = "Product.aspx?name=" + prodName + "&product_id=" + prodid + "&requestedPage=" + (currentPage - 1) + "&pageCount=" + pageCount;
				lnkNext.NavigateUrl = "Product.aspx?name=" + prodName + "&product_id=" + prodid + "&requestedPage=" + (currentPage + 1) + "&pageCount=" + pageCount;
			}

			lblPage.Text = prodName;
		}
	}
}

⌨️ 快捷键说明

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