CurrentPage++;
break;
case"first":
CurrentPage=0;
break;
case"last":
CurrentPage=PageCount-1;
break}
ViewState["currentPage"]=CurrentPage;
ListBind();
lbpageandTotal.Text=(CurrentPage+1)+"/"+PageCount.ToString();
}
protectedvoidbtgo_Click(objectsender,EventArgse)
{
CurrentPage=Int32.Parse(TextBox2.Text.ToString())-1;
PageCount=(int)ViewState["pageCount"];
if(CurrentPage<0)
{CurrentPage=0;}
if(CurrentPage>PageCount-1)
{CurrentPage=PageCount-1;}
//ViewState["currentPage"]=CurrentPage;
ListBind();
lbpageandTotal.Text=(CurrentPage+1)+"/"+PageCount.ToString();
}
MasterPage.master中:
源代码:
protectedvoidPage_Load(objectsender,EventArgse)
{
HtmlAnchorlnkhome=newHtmlAnchor();
lnkhome.InnerText="主页";
lnkhome.HRef="default.aspx";
PlaceHolder1.Controls.Add(lnkhome);
LiteralmyLt=newLiteral();
myLt.Text=">>>";
PlaceHolder1.Controls.Add(myLt);
if(Request.QueryString["CategoryId"]!
=null)
{
HtmlAnchorlnkProsuct=newHtmlAnchor();
lnkProsuct.InnerText=Request.QueryString["CategoryId"].ToString();
lnkProsuct.HRef="Products.aspx?
page=0&CategoryId="+Request.QueryString["CategoryId"].ToString();
PlaceHolder1.Controls.Add(lnkProsuct);
}
Label1.Text=Page.Title.ToString();
Page.Title=string.Format(".netpetshop:
:
{0}",Page.Title.ToString());
if(Request.QueryString["ProductId"]!
=null)
{SqlConnectionmyconn=newSqlConnection(DB.CreateConnStr());
SqlCommandmyCommand=newSqlCommand("selectCategoryIdfromproductwhereProductId='"+Request.QueryString["ProductId"].ToString()+"'",myconn);
myconn.Open();
stringCategoryId=myCommand.ExecuteScalar().ToString();
myconn.Close();
HtmlAnchorlnkProsuct1=newHtmlAnchor();
lnkProsuct1.InnerText=CategoryId;
lnkProsuct1.HRef="Products.aspx?
page=0&CategoryId="+CategoryId+"";
PlaceHolder1.Controls.Add(lnkProsuct1);
Literalmyll=newLiteral();
myll.Text=">>>";
PlaceHolder1.Controls.Add(myll);
HtmlAnchorlnkItem=newHtmlAnchor();
SqlConnectionmyconn1=newSqlConnection(DB.CreateConnStr());
SqlCommandmyCommand1=newSqlCommand("selectnamefromproductwhereProductId='"+Request.QueryString["ProductId"].ToString()+"'",myconn);
myconn.Open();
stringname=myCommand1.ExecuteScalar().ToString();
myconn.Close();
lnkItem.InnerText=name;
lnkItem.HRef="Items.aspx?
productId=&categoryId="+name+"";
PlaceHolder1.Controls.Add(lnkItem);}}
protectedvoidLinkButton1_Click(objectsender,EventArgse)
{Response.Redirect("SignIn.aspx");}
protectedvoidLinkButton2_Click(objectsender,EventArgse)
{Response.Redirect("ShoppingCart.aspx");}
Items页面中:
Item.aspx.cs中代码:
privatestringItemId;
privatestringCategoryId;privatestringproductName;
string_ItemId,_ItemName,pId,Qty;
intm;
floatUnitprice;
intCurrentPage,Pagesize,RecordCount,PageCount;
protectedvoidPage_Load(objectsender,EventArgse)
{
SqlConnectionmyconn=newSqlConnection(DB.CreateConnStr());
SqlCommandmyCommand=newSqlCommand("selectnamefromproductwhereProductId='"+Request.QueryString["ProductId"].ToString()+"'",myconn);
myconn.Open();
stringname=myCommand.ExecuteScalar().ToString();
myconn.Close();
Page.Title=name;
Pagesize=4;
//Page.Title=Request.QueryString["ItemId"].ToLower();
if(!
Page.IsPostBack)
{
ListBind();
CurrentPage=0;
ViewState["currentPage"]=CurrentPage;
PageCount=RecordCount/Pagesize;
if(RecordCount%Pagesize>0)
{PageCount=PageCount+1;}
ViewState["pageCount"]=PageCount;
}}
protectedvoidListBind()
{
SqlConnectionmyconn=newSqlConnection(DB.CreateConnStr());
SqlDataAdaptermyda=newSqlDataAdapter("selectb.*,c.*fromProductajoinItembona.ProductId=b.ProductIdjoinInventoryconb.ItemId=c.ItemIdwherea.ProductId='"+Request.QueryString["ProductId"].ToString()+"'",myconn);
DataSetmyds=newDataSet();
intStartIndex=CurrentPage*Pagesize;
myda.Fill(myds,StartIndex,Pagesize,"selectb.*,c.*fromPro