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

zhaozj2021-02-16  94

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 a general paging of DataGrid, DataList, Repeater --- 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 //} here

Public system.Web.ui.WebControls.DataGrid DataGrid {get {return} 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 repeater {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; // objPds.PageSize = pagenum display page number; // the specified data source objPds.DataSource = ds.Tables [ 0] .default referview; 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 "," "); // 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; // Display current page THIS.PAGENUM.TEXT = "Page:" 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 ();}} // DropDownList Selection change public void select () {this.lnkjump.NavigateUrl = System.Web.HttpContext.Current.Request.CurrentExecutionFilePath "Page =?" Convert.ToString (this.list.SelectedItem.Value);}

}

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

New Post(0)