剛開始學.Net時寫的分頁類

來源:互聯網
上載者:User

共用的分頁類,使用非常簡單,試合初學者使用,但效率較低,使用的是PagedDataSource分頁

public PagedDataSource GetPagedDataSource(DataSet MyDataSet,int PageSize,int PageNum,string AspxName,Label PageLable)
{
PagedDataSource PDS=new PagedDataSource();
PDS.AllowPaging=true;
PDS.PageSize=PageSize;
PDS.DataSource=MyDataSet.Tables[0].DefaultView;
int CurrentPage=0;
if(Convert.ToString(PageNum)!=null)
{
CurrentPage=int.Parse(PageNum.ToString());
}
else
{
CurrentPage=1;
}
PDS.CurrentPageIndex=CurrentPage-1;
int PageCount=PDS.PageCount;
string FirstPage=(PageNum==1)?("9"):("9");
string PrevPage=(PageNum==1)?("7"):("7");
string NextPage=(PageNum==(PageCount))?("8"):("8");
string LastPage=(PageNum==(PageCount))?(":"):(":");
PageLable.Text="總記錄: "+PDS.DataSourceCount+"   每頁: "+PageSize+"   總頁數: "+PageCount+""+FirstPage+"  "+PrevPage+"  "+NextPage+"  "+LastPage+"";
return PDS;
}
調用樣本
//PagedDataSource分頁
string MySql="Select * from C_Company";
int PageNum=(Request.QueryString["Page"]==null)?(1):(Convert.ToInt32(Request.QueryString["Page"]));
MyDataSet=MyData.GetDataSet(MySql,0,0,"Table");
PagedDataSource PDS=new PagedDataSource();
PDS=MyData.GetPagedDataSource(MyDataSet,10,PageNum,Request.CurrentExecutionFilePath+"?",Label1);
this.DataGrid1.DataSource=PDS;
this.DataGrid1.DataBind();

聯繫我們

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

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

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.