通用的分頁類(不執行sql,直接綁定資料)

來源:互聯網
上載者:User
分頁|資料|執行 資料分頁一直以來是比較頭疼的問題,不少的分頁控制項也隨之產生。但是我用過的幾個控制項,本身都要執行SQL,對預存程序支援不好,為了方便,特別寫了個通用分頁類,利用PagedDataSource來實現DataGrid,DataList,Repeater的分頁。完成上一頁,下一頁,
最後一頁,最前一頁,總頁數,當前頁數,跳轉這些基本的功能。



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-本類提供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: 在此處添加建構函式邏輯
//
}

public System.Web.UI.WebControls.DataGrid Datagrid
{
get
{
return 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 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;
//指定資料來源
objPds.DataSource = ds.Tables[0].DefaultView;
int CurPage;
//綁定dropdownlist資料
for(int i=1;i<=objPds.PageCount;i++)
{
this.list.Items.Add(i.ToString());
}
this.list.Items.Insert(0,new ListItem("頁數",""));
//確定當前頁數
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;


相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。