ASP.NET's DataGrid paging control, under the Oracle database, each time only the data on the previous page, does not use th

xiaoxiao2021-03-06  89

It is not good to write for reference only.

GridPager.ascx: <% @ Control Language = "c #" AutoEventWireup = "false" Codebehind = "GridPager.ascx.cs" Inherits = "Test.BaseClass.GridPager" TargetSchema = "http://schemas.microsoft.com/intellisense / IE5 "%> 1 /// gridpager.ascx.cs: using system; using system.data; using system. Drawing; using system.web; using system.web.ui .WebControls; namespace Test.BaseClass {public class GridPager: System.Web.UI.UserControl {#region class variables protected System.Web.UI.WebControls.LinkButton lbtnNext; protected System.Web.UI.WebControls.LinkButton lbtnPage10; protected System .Web.ui.webcontrols.linkbutton lbtnpage9; protected system.web.ui.webcontrols.linkButton lbtnpage8;

protected System.Web.UI.WebControls.LinkButton lbtnPage7; protected System.Web.UI.WebControls.LinkButton lbtnPage6; protected System.Web.UI.WebControls.LinkButton lbtnPage5; protected System.Web.UI.WebControls.LinkButton lbtnPage4; protected System .Web.UI.WebControls.LinkButton lbtnPage3; protected System.Web.UI.WebControls.LinkButton lbtnPage2; protected System.Web.UI.WebControls.LinkButton lbtnPage1; protected System.Web.UI.WebControls.LinkButton lbtnPre; #endregion #region ///

/// No .: 01 /// Content Summary: Turn the object: DataGrid control. /// public dataGrid THEGRID; /// /// Number: 02 /// Content Summary: Display the label of the query result record number, may not be set, indicating that there is no need to display. /// public label labelrowscount;

///

/// Number: 03 /// Content Summary: The label of the total number of query results is displayed, which may not be set, indicating that there is no need to display. /// public label labelpagecount;

///

/// Number: 04 /// Content Summary: Displays the label of the current page number, may not be set, indicating that there is no need to display. /// public label labelpageindex;

///

/// No .: 05 /// Content Summary: Query data SQL statement. . /// private string SelectSQL {get {if (! ViewState [this.ClientID "_ SelectSQL"] = null) return ViewState [this.ClientID "_ SelectSQL"] ToString (); else return string.Empty;} Set {viewState [this.clientID "_ selectsql"] = value;}} // selectSQL end /// /// No .: 06 /// Content Summary: The number of rows displayed per page. /// public int pageSizes {get {if (viewState [this.clientid "_ pagesizes"]! = null) return (int) viewState [this.clientid "_ pagesizes"]; else return 20;} set {viewState [this.clientID "_ pagesizes"] = value;}} // pagesizes end

///

/// Number: 07 /// Content Summary: The total number of pages. /// private int PageCount {get {if (! ViewState [this.ClientID "_ PageCount"] = null) return (int) ViewState [this.ClientID "_ PageCount"]; else return 0;} set {ViewState [this.clientid "_ pageCount"] = value;}} // pageCount end

///

/// No .: 08 /// Content Summary: Current page number. /// private int CurrentPageIndex {get {if (ViewState [this.ClientID "_ CurrentPageIndex"] = null!) Return (int) ViewState [this.ClientID "_ CurrentPageIndex"]; else return 0;} set {ViewState [this.ClientID "_ CurrentPageIndex"] = value; if (this.LabelPageIndex = null!) this.LabelPageIndex.Text = (value 1) .ToString ();}} private LinkButton [] PageButtons {get {return new LinkButton [ ] {lbtnPage1, lbtnPage2, lbtnPage3, lbtnPage4, lbtnPage5, lbtnPage6, lbtnPage7, lbtnPage8, lbtnPage9, lbtnPage10};}} # endregion # region /// /// method number: 01 /// Summary: initial page . /// private void page_load (object sender, system.eventargs e) {}

///

/// method number: 02 /// Content Summary: Set the control associated with this control. /// /// DataGrid control, you must provide /// Show the query result record number, you can enter NULL, Indicates that there is no need to display the "LBLPAGECount"> display the number of query results, you can enter NULL, indicating that there is no need to display /// display the current page number tag can enter null, meaning without show public void InitPagerControls (DataGrid mDataGrid, label lblRowsCount, label lblPageCount, label lblPageIndex) {mDataGrid.AllowPaging = false; this.TheGrid = mDataGrid; this.LabelRowsCount = lblRowsCount "This.labelpageCount; this.labelpageindex = lblpageindex;} /// /// method number: 03 /// Content summary: Change the query condition to re-query data. /// /// The SQL statement of the query, always use this statement to get the data set until the next call is called public void loadData (String SELECTSQL) {// Save new SQL statement this.selectsql = selectsql;

// Statistically eliminate the number of requirements INT MROWCOUNT = 0; String Tmpsql = "STRING TMPSQL =" SELECT Count (*) from (" SelectSql ") T "; Database DB = New Database (); system.data.oledb.oledbDataReader TMPDR = DB.GetdataReaderfromsql (Tmpsql); if (Tmpdr.Read ()) MROWCOUNT = Convert.Toint32 (TMPDR [0]); // Release data connection TMPDR.CLOSE (); db.dispose ();

// If necessary, the number of data is displayed (this.labelrowscount! = Null) this.labelrowscount.text = MROWCOUNT.TOSTRING (); // Statistics Total number, if needed, display THISPAGECOUNT = (int ) Math.ceiling ((Double) MROWCOUNT / ((Double) PageSizes); if (this.labelpagecount! = Null) this.labelpagecount.text = this.pagecount.toString ();

// DataGrid's current page Back to the first page, the button also returns the status of the first page this.currentpageIndex = 0; this.changepageButtons (0);

// Query the first page Data this.lbtnpages_click (this.pagebuttons [0], null);

}

///

/// method number: 04 /// Content Summary: Query the requirements of the qualified data and bind DataGrid display. /// private void binddata () {string selectsql = this.selectsql;

IF (SelectSql! = String.empty) {database DB = new database (); // This is my own data operation class

INT rowstart = (currentPageIndex * pagesizes) 1; // Starter number INT Rownd = (CurrentPageIndex 1) * Pagesizes; // End serial number of the current page

String querysql = "SELECT * FROM (SELECT T1. *, ROWNUM SN from (" SELECTSQL ") T1) T2" "Where t2.sn between" rowstart.tostring () "and" rowend.toString ( ); / / Query the database read the eligible data DATATABLE TB = DB.GetDataTableFromSQL (QuerySQL);

// Bind DataGrid display thegrid.datasource = Tb; THEGRID.DATABIND ();

db.dispose ();}}

///

/// method number: 05 /// Content summary: Change the state of the flip page button, such as display 21, 22, ... 30. /// Private void callbuttons (int mark) {int TmpRem = 0; int Tmpdiv = Math.divrem (this.pagecount, 10, out tmpRem); if (tmpRem == 0) TMPREM = 10; // All buttons restore the default status for (int i = 0; i <10; i ) {int Pagenum = mindex * 10 i 1; this.pageButtons [i] .text = Pagenum.toString (); this.pageButtons [ I] .visible = true; this.pageButtons [i] .enabled = true; this.pageButtons [i] .font.size = system.Web.ui.WebControls.FontUnit.xsmall;} // end of for (int i = 0; i <10; i )

THISIBLE = true; this.lbtnnext.visible = true;

// If you are currently from 1 to 10 pages, then the front "..." if (mindex == 0) lbtnpre.visible = false; // If it is currently the last page, do not show "" ... "; and guarantee that the displayed flip button does not exceed the maximum number of pages if (MINDEX == Tmpdiv) {lbtnnext.visible = false; for (int i = 9; i> tmpRem-1; i = i-1) this.pageButtons [i] .visible = false;}}

///

/// method number: 06 /// Content Summary: Show the top ten page number. /// private void lbtnpre_click (object sender, system.eventargs e) {this.changepageButtons ((int) Math.floor (Math.max (this.currentpageIndex - 10, 0) / 10)); LBTNPAGES_CLICK (this.pageButtons [9], null);

///

/// method number: 07 /// Content Summary: The last ten page numbers are displayed. /// private void lbtnnext_click (object sender, system.eventargs e) {this.changepagebuttons ((int) Math.floor (Math.max (this.currentpageIndex 10); this. LBTNPAGES_CLICK (this.pageButtons [0], null);} /// /// method number: 08 /// Content Summary: Query the new page. /// private void lbtnPages_Click (object sender, System.EventArgs e) {LinkButton tmpLBtn = sender as LinkButton; int pageIndex = Convert.ToInt32 (tmpLBtn.Text.Trim ()) - 1; this.CurrentPageIndex = pageIndex ;

Foreach (LinkButton Mlbtn in this.pageButtons) {mlbtn.enabled = true; mlbtn.font.size = system.web.ui.webcontrols.fontunit.xsmall;

TMPLBTN.ENABLED = false; tmplbtn.font.size = system.web.ui.webcontrols.fontunit.small;

THIS.BINDDATA ();

#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // initializeComponent (); base.oninit (e);} ///

/// Designer Support required method - Do not use code editor // to modify the contents of this method. /// private void InitializeComponent () {this.lbtnPre.Click = new System.EventHandler (this.lbtnPre_Click); this.lbtnPage1.Click = new System.EventHandler (this.lbtnPages_Click); this.lbtnPage2 .Click = new System.EventHandler (this.lbtnPages_Click); this.lbtnPage3.Click = new System.EventHandler (this.lbtnPages_Click); this.lbtnPage4.Click = new System.EventHandler (this.lbtnPages_Click); this. lbtnPage5.Click = new System.EventHandler (this.lbtnPages_Click); this.lbtnPage6.Click = new System.EventHandler (this.lbtnPages_Click); this.lbtnPage7.Click = new System.EventHandler (this.lbtnPages_Click); this .lbtnPage8.Click = new System.EventHandler (this.lbtnPages_Click); this.lbtnPage9.Click = new System.EventHandler (this.lbtnPages_Click); this.lbtnPage10.Click = new System.EventHandler (this.lbtnPages_Click); THIS.LBTNNEXT.Click = New System. EventHandler (this.lbtnnext_click; this.load = new system.eventhandler (this.page_load);} #ENDREGION

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

New Post(0)