1. Insert the following code in Page_Load.
protected voidPage_Load (Objectsender, EventArgs e) { if(request.params["page"] !=NULL&& request.params["page"]. Trim ()! ="") {page= (Convert.ToInt32 (request.params["page"])); Maxpage=Databind (page, maxnum); Lblmaxnum.text=Maxpage. ToString (); } Else{page=1;Maxpage =Databind (page, maxnum); Lblmaxnum.text=Maxpage. ToString (); } }
2, the DataBind method code is as follows. Pagenum represents the first few pages, and Maxnum represents the maximum number of data per page.
Public intDatabind (intPagenum,intmaxnum) {Zygzsdataclassesdatacontext Context=NewZygzsdataclassesdatacontext (); varCount =context. T_paper.count (); intMaxpage = (count/maxnum) +1; if(Maxpage >=2) { varRes = context. T_paper.skip (Pagenum-1) *maxnum). Take (Maxnum); Rptlist.datasource=Res; Rptlist.databind (); } Else { varres =context. T_paper.take (Maxnum); Rptlist.datasource=Res; Rptlist.databind (); } returnMaxpage; }
3, the next page button, the code is as follows.
protected voidLbtnnext_click (Objectsender, EventArgs e) { if(Page <maxpage) { if(request.params["page"] !=NULL&& request.params["page"]. Trim ()! ="") {page= (Convert.ToInt32 (request.params["page"])) +1; Response.Redirect ("paper.aspx?page="+page. ToString ()); } Else{page=2; Response.Redirect ("paper.aspx?page="+page. ToString ()); } } }
ASP. NET uses QueryString to implement pagination of multiple database data