protected void Page_Load(object sender, System.EventArgs e) { if(!this.IsPostBack) {//填充一个dataSet OleDbConnection con = DB.createCon(); con.Open(); OleDbDataAdapter sda1 = new OleDbDataAdapter("select * from Message order by id desc",con); DataSet ds1 = new DataSet(); sda1.Fill(ds1);//PageDataSource 是vs提供的分页控件 .可以直接使用 PagedDataSource pds = new PagedDataSource(); pds.DataSource=ds1.Tables[0].DefaultView; pds.AllowPaging=true; pds.PageSize=10; int CurPage; //当前页面从Page查询参数获取 if(Request.QueryString["Page"]!=null) { CurPage=Convert.ToInt32(Request.QueryString["Page"]);
} else { CurPage=1; } pds.CurrentPageIndex=CurPage-1;//当前页是从0开始算的.所以要-1 this.lblCurrentPage.Text=CurPage.ToString();//判断是否是第一页或者最后一页,不用计算.直接调用方法 if(!pds.IsFirstPage) { this.inkPrev.NavigateUrl=Request.CurrentExecutionFilePath+"?Page="+Convert.ToString(CurPage-1); } if(!pds.IsLastPage) { this.lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+"?Page="+Convert.ToString(CurPage+1); } this.DataList1.DataSource=pds; this.DataList1.DataBind(); this.DataList1.DataKeyField.ToString(); con.Close(); } // 在此处放置用户代码以初始化页面 } 这个写着确实简单.不需要费什么劲.所有功能都集成好了,直接调用就行了。功能不是很多,比如跳转一类的都没有写,所以称之为傻瓜型分页系统。。供新手学习。。
转载于:https://www.cnblogs.com/arcana1985/archive/2007/01/18/623399.html
