📄 category.aspx.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 Category : 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 = 0;
protected void Page_Load(object sender, System.EventArgs e) {
// update page header with category we are displaying
lblPage.Text = Request.QueryString["category_id"];
// if pageindex
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() {
// 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;
Components.Product product = new Components.Product();
ProductResults[] results = product.GetList(lblPage.Text, 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 = "Category.aspx?category_id=" + lblPage.Text + "&requestedPage=" + (currentPage - 1) + "&pageCount=" + pageCount;
lnkNext.NavigateUrl = "Category.aspx?category_id=" + lblPage.Text + "&requestedPage=" + (currentPage + 1) + "&pageCount=" + pageCount;
}
else {
// there is only one page, hide both buttons
lnkPrevious.Visible = lnkNext.Visible = false;
lnkPrevious.NavigateUrl = "Category.aspx?category_id=" + lblPage.Text + "&requestedPage=" + (currentPage - 1) + "&pageCount=" + pageCount;
lnkNext.NavigateUrl = "Category.aspx?category_id=" + lblPage.Text + "&requestedPage=" + (currentPage + 1) + "&pageCount=" + pageCount;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -