📄 shoplist.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class shopList : System.Web.UI.Page
{
public static int TotalPage;//定义变量来保存总页数
public int CurPage;//定义变量来保存当前页索引
public int Tnum;//总条数
public int EachPage;//每页总条数
public SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnStr"]);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//绑定 分类列表
String sql = "SELECT * FROM PType where parentId=0";
SqlCommand command = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader dr = command.ExecuteReader();
Repeater1.DataSource = dr;
Repeater1.DataBind();
dr.Close();
conn.Close();
//绑定 类别所对应的店铺列表
string mysql = "";
string strID = "0";
if (Request.QueryString["categoryid"] != null)
{
strID = Request.QueryString["categoryid"].ToString();
if (strID.Equals("0"))
{
mysql = "SELECT * FROM DianPuDetail";
}
else
{
mysql = "SELECT * FROM DianPuDetail where DianPuClass=" + strID;
}
}
else
{
mysql = "SELECT * FROM DianPuDetail";
}
/*
SqlCommand mycommand=new SqlCommand(mysql,conn);
conn.Open();
SqlDataReader mydr=mycommand.ExecuteReader();
*/
SqlDataAdapter da = new SqlDataAdapter(mysql, conn);
DataSet ds = new DataSet();
da.Fill(ds, "Table");
PagedDataSource objPage = new PagedDataSource();//创建分页类
objPage.DataSource = ds.Tables["Table"].DefaultView;//设置数据源
objPage.AllowPaging = true;
objPage.PageSize = 5;
if (Request.QueryString["Page"] != null)
{
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
CurPage = Math.Min(CurPage, objPage.PageCount);
CurPage = Math.Max(CurPage, 1);
}
else
{
CurPage = 1;
}
objPage.CurrentPageIndex = CurPage - 1;
TotalPage = objPage.PageCount;
Tnum = objPage.DataSourceCount;
EachPage = objPage.Count;
lblCurPage.Text = "第 " + CurPage.ToString() + " / " + TotalPage.ToString() + " 页";
lblTnum.Text = "共: " + Tnum.ToString() + " 条记录 ";
lblEachPage.Text = "每页有: " + EachPage.ToString() + " 条记录";
if (objPage.CurrentPageIndex != 0)
lnkFirst.NavigateUrl = Request.CurrentExecutionFilePath + "?categoryid=" + strID + "&Page=" + Convert.ToString(1);
if (objPage.CurrentPageIndex != TotalPage - 1)
lnkLast.NavigateUrl = Request.CurrentExecutionFilePath + "?categoryid=" + strID + "&Page=" + Convert.ToString(TotalPage);
if (!objPage.IsFirstPage)
lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?categoryid=" + strID + "&Page=" + Convert.ToString(CurPage - 1);
if (!objPage.IsLastPage)
lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?categoryid=" + strID + "&Page=" + Convert.ToString(CurPage + 1);
Repeater2.DataSource = objPage;
Repeater2.DataBind();
//mydr.Close();
conn.Close();
//查询 当前的类别名
String mysql2 = "SELECT * FROM PType where category_ID=" + strID;
SqlCommand mycommand2 = new SqlCommand(mysql2, conn);
conn.Open();
SqlDataReader mydr2 = mycommand2.ExecuteReader();
if (mydr2.Read())
{
Label1.Text = mydr2["category_name"].ToString();
}
else
{
Label1.Text = "所有分类";
}
//mydr.Close();
conn.Close();
}
}
protected void btnPage_Click(object sender, EventArgs e)
{
int PageNum = 0;
if (!Request.Form["txtPage"].Equals(""))
PageNum = Convert.ToInt32(Request.Form["txtPage"]);
if (PageNum <= 0 || PageNum > TotalPage)
Response.Redirect(Request.CurrentExecutionFilePath + "?categoryid=" + Request.QueryString["categoryid"].ToString() + "&Page=" + Convert.ToString(1));
else
Response.Redirect(Request.CurrentExecutionFilePath + "?categoryid=" + Request.QueryString["categoryid"].ToString() + "&Page=" + Convert.ToString(PageNum));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -