Universal paging class (not executing SQL, direct binding data)

xiaoxiao2021-03-06  97

Data page has always been a problem with a more headache, and a lot of paging controls are also generated. But I have used several controls, it is necessary to perform SQL, support the storage process, for convenience, especially writing a general paging class, using PagedDataSource to implement the paging of DataGrid, DataList, Repeater. Complete the previous page, the next page, the last page, the top page, the total number of pages, the number of current pages, and the basic features are jumped.

using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web .Ui.htmlControls; Namespace aspnetPager {/// /// NetPager- This class provides DataGrid, DataList, Repeater general paging - Jierry 04-7-19 /// public class netpager: system.web.ui.page {private System.Web.UI.WebControls.DataGrid datagrid = null; private System.Web.UI.WebControls.DataList datalist = null; private System.Web.UI.WebControls.Repeater repeater = null; private System.Web.UI. WebControls.HyperLink lnknext; private System.Web.UI.WebControls.HyperLink lnkprev; private System.Web.UI.WebControls.HyperLink lnkfist; private System.Web.UI.WebControls.HyperLink lnklast; private System.Web.UI.WebControls. HyperLink lnkjump; private System.Web.UI.WebControls.Label pagenum; private System.Web.UI.WebControls.Label pagecount; private System.Web.UI.WebControls.DropDownList list; public netpager () {// // Todo: Add constructor logic //} public system.web.ui.webcontrols.DataGrid DataGrid;} set {this.DataGrid;} set {this.dataGrid = value;}} public system. Web.ui.WebControls.Datalist Datalist {get {return this.datalist;} set {this.datalist = value;}} public system.Web.ui.WebControls.repeater review {get {return this.repeater;} set {this .repeater = value;}} public System.Web.UI.WebControls.HyperLink Lnkprev {get {return this.lnkprev;} set {this.lnkprev = value;}} public System.Web.UI.WebControls.HyperLink Lnknext {get {Return this.lnknext;} set {this.lnknext = value;

}} Public System.Web.UI.WebControls.HyperLink Lnkfist {get {return this.lnkfist;} set {this.lnkfist = value;}} public System.Web.UI.WebControls.HyperLink Lnklast {get {return this.lnklast ;} set {this.lnklast = value;}} public System.Web.UI.WebControls.HyperLink Lnkjump {get {return this.lnkjump;} set {this.lnkjump = value;}} public System.Web.UI.WebControls .Label pagenum {get {return this.pagenum;} set {this.pagenum = value;}} public System.Web.UI.WebControls.Label Pagecount {get {return this.pagecount;} set {this.pagecount = value; }} public System.Web.UI.WebControls.DropDownList List {get {return this.list;} set {this.list = value;}} public void datapage (DataSet ds, int pagenum) {PagedDataSource objPds = new PagedDataSource () Objpds.allowpaging = true; / / The number per page Objpds.pageSize = Pagenum; / / Specify the data source Objpds.DataSource = DS.Tables [0] .defaultView; int curpage; // Bind DROPDOWNLIST data for (int i = 1; i <= objPDs.PageCount; i ) {this.list.Items.Add (i.tostring ()); } This.list.Items.Insert (0, new listitem ("" page "," "); // Determine the current page number if (System.Web.httpContext.current.Request.Params [" Page "]! = NULL) {CURPAGE = Convert.Toint32 (System.Web.httpContext.current.Request.Params ["page"]);} else {curpage = 1;} Objpds.currentpageIndex = CURPAGE-1; // Displays the current number of pages this THIS .pagenum.text = page Number of pages: " Curpage.Tostring (); // Show total pages this.pagecount.text =" A total of " Objpds.PageCount " page ";

/ / Next IF (! Objpds.islastPage) {lnknext.navigateURL = system.web.httpContext.current.request.currentexecutionFilePath "? Page =" Convert.TOString (CURPAGE 1);} // Previous page IF (! objPds.IsFirstPage) {lnkprev.NavigateUrl = System.Web.HttpContext.Current.Request.CurrentExecutionFilePath Convert.ToString (CurPage-1) "page =?";} // first page if (CurPage = 1!) {lnkfist.NavigateUrl = System.Web.HttpContext.Current.Request.CurrentExecutionFilePath "? Page =" Convert.ToString (1);} // last page if (! CurPage = objPds.PageCount) {lnklast.NavigateUrl = System .Web.HttpContext.Current.Request.CurrentExecutionFilePath Convert.ToString (objPds.PageCount) "Page =?";} // bind datagrid if (this.datagrid = null!) {datagrid.DataSource = objPds; datagrid.DataBind (); // Bind Datalist if (this.DataList! = Null) {data.dataSource = Objpds; DataList.Database ();} // Bind Repeater if (this.repeater! = Null) {REPEATER.DATASOURCE = Objpds; Repeater.Database ();}} // Dropdow nlist option to change public void select () {this.lnkjump.NavigateUrl = System.Web.HttpContext.Current.Request.CurrentExecutionFilePath Convert.ToString (this.list.SelectedItem.Value) "Page =?";}}} use : 1. Add ASPNETPAGER.DLL in the reference 2.using aspnetPager; 3.Private NetPager Pager; 4.page_load () if (! Ispostback) {Pager = new netpager (); Pager.DataGrid = this.dataGrid1; Pager .Datalist1; Pager.repeater = this.repeater1; Pager.lnknext = this.hyperlink1; PagerLink1; Pager.Lnkprev = this.lnkprev; Pager.Lnklast = this.lnklast; Pager.lnkfist =

THIS.LNKFIST; PAGER.PAGENUM = this.label1; Pager.PageCount = this.Label2; Pager.list = this.dropdownList1; DataSet DS = New Dataset (); ds.readxml (Server.MAppath ("test.xml") ); pager.datapage (ds, 5);} 5.private void DropDownList1_SelectedIndexChanged (object sender, System.EventArgs e) {pager = new netpager (); pager.List = this.DropDownList1; pager.Lnkjump = this.HyperLink3; Author Blog:

http://blog.9cbs.net/jierry007/

转载请注明原文地址:https://www.9cbs.com/read-125584.html

New Post(0)