DataList paging (Codebehind section)

zhaozj2021-02-16  54

datalist tab (the codebehind part) Links: Andy.m Date: 2003-07-12 Popularity: 30using System; using System.Collections; using System.Configuration; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace cj168.Web {///

/// Summary description for search /// public class search: System.Web.UI.Page {protected System.Web.UI.WebControls.DataList datalistSearchResult; protected System.Web.UI.WebControls. .Label lblTxtSearch; protected System.Web.UI.WebControls.Label lblRecordCount; protected System.Web.UI.WebControls.Label lblCurrentPage; protected System.Web.UI.WebControls.Label lblPageCount; protected System.Web.UI.WebControls.Label LBLPageRange; protected system.Web.ui.WebControls.LinkButton lbnprevpage; protected system.web.ui.webcontrols.link Button lbnNextPage; String txtSearch; int PageSize, RecordCount, PageCount, CurrentPage; public search () {Page.Init = new System.EventHandler (Page_Init);} private void Page_Load (object sender, System.EventArgs e) {// Put User code to initialize the page head txtsearch = request.params ["txtsearch"]; if (txtsearch! = null) {txtsearch = txtsearch.replace ("'", "); lbltxtSearch.text = txtsearch; // Set PageSize PageSize = 10; // Calculate how much records of total recording recordcount =

CalculateRecord (); lblrecordcount.text = RecordCount.toString (); if (! Page.ispostback) {dosearch (); currentpage = 0; viewState ["pageindex"] = 0; // How many pages of total Calculation PageCount = Recordcount / PageSize; if (RecordCount% PageSize> 0) PageCount = PageCount 1; lblPageCount.Text = PageCount.ToString (); ViewState [ "PageCount"] = PageCount;}}} // calculate total number of records public int CalculateRecord ( ) {CJ168.DataAccess.magsdb dosearch = new cj168.dataaccess.magsdb (); return dosearch.getsearchResultcount (txtsearch);} void dosearch () {Int StartIndex; int fromItem, toItem; // set imported from a final address StartIndex = CurrentPage * PageSize; cj168.DataAccess.MagsDB DoSearch = new cj168.DataAccess.MagsDB (); datalistSearchResult.DataSource = DoSearch.GetSearchResult (txtSearch, StartIndex, PageSize); datalistSearchResult.DataBind ( ); lbnNextPage.Enabled = true; lbnPrevPage.Enabled = true; if (CurrentPage == (PageCount-1)) lbnNextPage.Enabled = false; if (CurrentPage == 0) lbnPrevPage.Enabled = false; lblCurrentPage.Text = (CurrentPage 1) .toString (); fromItem = startIndex 1;

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

New Post(0)