In general, there are 3 methods for paging, which are the data display space of ASP. such as the GridView page, third-party paging control such as Aspnetpager, stored procedure paging, etc. Here is a summary of each.
The first: The use of the GridView with pagination, this is the simplest method of paging.
The method of the foreground
<asp:gridview id= "GridView1" allowpaging= "true" runat= "Server" onpageindexchanging= "gridview1_pageindexchanging "Pagesize=" 3 "> </asp:GridView>
Background method:
Using System; Using System.Collections.Generic; Using System.Linq; Using System.Web; Using System.Web.UI; Using System.Web.UI.WebControls; Using JXSoft.TicketManage.Model; Using JXSoft.TicketManage.BLL; Using System.Text.RegularExpressions; Using System.Data; namespace JXSoft.TicketManage.Web {public partial class Test:System.Web.UI.Page {protected void Page_Load (object Sende R, EventArgs e) {if (! IsPostBack) {binddata ();}} protected void Binddata () {DataTable dt=new DataTable (); dt. Columns.Add ("ID"); Dt. Columns.Add ("Name"); for (int i = 0; i < 10;i++) {dt. Rows.Add (i.ToString (), i.tostring ()); } this. Gridview1.datasource = DT; This. Gridview1.databind (); } protected void Gridview1_pageindexchanging (object sender, Gridviewpageeventargs e) {this. Gridview1.pageindex = E.newpageindex; Binddata (); } } }
Second: Paging using the AspNetPager.dll of the personalization display
You need to add a reference to Aspnetpager.dll here
Front desk:
<form id= "Form1" runat= "Server" > <div> <asp:gridview id= "GridView1" runat= "Server" > </asp: gridview> <webdiyer:aspnetpager id= "AspNetPager1" runat= "Server" custominfohtml= "page%currentpageindex%, total% pagecount% page,%pagesize% per page "firstpagetext=" Home "lastpagetext=" last "layouttype=" Table "nextpagetext=" Next " onpagechanging= "aspnetpager1_pagechanging" pageindexboxtype= "DropDownList" pagingbuttonlayouttype= "Span" prevpagetext= "prev" showcustominfosection= "left" showpageindexbox= "Always" submitbuttontext= "Go" pagesize= "4" textafterpageindexbox= "page" textbeforepageindexbox= "Go" > </webdiyer:AspNetPager> </div> </form>
Background:
Using System; Using System.Collections.Generic; Using System.Linq; Using System.Web; Using System.Web.UI; Using System.Web.UI.WebControls; Using JXSoft.TicketManage.Model; Using JXSoft.TicketManage.BLL; Using System.Text.RegularExpressions; Using System.Data; namespace JXSoft.TicketManage.Web {public partial class Test:System.Web.UI.Page {protected void Page_Load (object Sende R, EventArgs e) {if (! IsPostBack) {binddata ();}} protected void Binddata () {DataTable dt=new DataTable (); dt. Columns.Add ("ID"); Dt. Columns.Add ("Name"); for (int i = 0; i < 10;i++) {dt. Rows.Add (i.ToString (), i.tostring ()); DataSet ds = new DataSet (); Ds. Tables.add (DT); Pager (this. GridView1, this. AspNetPager1, DS); } protected void Pager (GridView dl, Wuqi.Webdiyer.AspNetPager ANP, System.Data.DataSet DST) {PagedDataSource PDS = new Pa Geddatasource (); Pds. DataSource = DST. Tables[0]. DefaultView; Pds. AllowPaging = true; Anp. RecordCount = DST. Tables[0]. Defaultview.count; Pds. CurrentPageIndex = ANP. CurrentPageIndex-1; Pds. PageSize = ANP. PageSize; Dl. DataSource = PDS; Dl. DataBind (); } protected void Aspnetpager1_pagechanging (Object src, Wuqi.Webdiyer.PageChangingEventArgs e) { Aspnetpager1.currentpageindex = E.newpageindex; Binddata (); } } }
Third: Paging with Aspnetpager combined with stored procedures
This method is slightly more complex to page, but can handle large amounts of data.
Front desk:
<asp:gridview id= "GridView1" runat= "Server" cssclass= "Gridtable" autogeneratecolumns= "false" onrowdatabound= " GridView1_RowDataBound "> </asp:GridView> <webdiyer:aspnetpager id=" AspNetPager1 "runat=" Server " Custominfohtml= "Page%currentpageindex%, total%pagecount% pages,%pagesize% per page" firstpagetext= "Home" lastpagetext= "last" LayoutType = "Table" nextpagetext= "next page" onpagechanged= "aspnetpager1_pagechanged" pageindexboxtype= "DropDownList" Pagingbuttonlayouttype= "Span" prevpagetext= "prev" showcustominfosection= "left" showpageindexbox= "always" Submitbuttontext= "Go" pagesize= "4" textafterpageindexbox= "page" textbeforepageindexbox= "Go" > </webdiyer: Aspnetpager>
Background:
The binding method needs to pass Aspnetpager's two properties protected void DataBind () {DataSet ds = Reportquerybll.gettcikdetailreport ( This.txtstartdate.text,this.txtenddate.text,int. Parse (this. Dropdownlistpartment1.selectedvalue), This.txtpayperson1.text,this.txtticketnum.text,this.txtticketno.text, ASPNETPAGER1.STARTRECORDINDEX,ASPNETPAGER1.ENDRECORDINDEX);//Note the last two parameters are Aspnetpager properties. This. Gridview1.datasource = ds; This. Gridview1.databind (); }//Paging Control page index Change event protected void aspnetpager1_pagechanged (Object src, EventArgs e) {BINDDETAILREPORTTOGV ();}//page_base The first number of data bars that need to be loaded in the DataSet ds = Reportquerybll.getdetail (This.txtStartDate.Text, this.txtEndDate.Text, Int. Parse (this. Dropdownlistpartment1.selectedvalue), This.txtPayPerson1.Text, This.txtTicketNum.Text, This.txtTicketNo.Text); This. Aspnetpager1.recordcount = ds. Tables[0]. Rows.Count; BINDDETAILREPORTTOGV ();
The stored procedure used here is more complicated, because the SQL statement is not able to be put into the view, and can not be directly isolated from the table results, this stored procedure is a bit perverted, if a friend saw, hope to point.
In fact, the core of the stored procedure is:
create PROCEDURE [dbo]. [p_getpagedorders2005] (@startIndex int, @endindex int) As SELECT * FROM (select Row_number () over (ORDER by IPid DESC) as rownum, [Ipid],[ipfrom],[ipto],[iplocation],[ipcity],[ip Tonumber],[ipfromnumber] from Ipinfo) as U WHERE rownum between @startIndex and @endIndex GO