共享的分页类,使用非常简单,试合初学者使用,但效率较低,使用的是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();
您的评论
·本站管理人员有权在不通知用户的情况下删除不符合规定的评论信息或留做证据
·请客观的评价您所看到的资讯,提倡就事论事,杜绝漫骂和人身攻击等不文明行为

收藏到QQ书签