大概就是这样,可以把分页的方法分离出来.等等看其他人有没有更好的方法.//当前页号int curPage = 1;// 页面大小const int PAGE_SIZE = 3;private void Page_Load(object sender, System.EventArgs e) { if (Request["pg"] != null) curPage = Convert.ToInt32(Request["pg"]); if (!this.IsPostBack) { int recordCo; //GetAllInfo方法返回的是DT集合 DataTable dt = dal.GetAllInfo( curPage, PAGE_SIZE, out recordCo );
//根据记录总数和页大小计算页面总数。 int pageCount = recordCo / PAGE_SIZE; if (recordCo % PAGE_SIZE != 0) pageCount ++;
this.DataList1.DataSource = dt; this.DataList1.DataBind();if (curPage > 1) { this.hl1.NavigateUrl = "?pg=1" ;//首页 this.hl2.NavigateUrl = "?pg=" + (curPage - 1 );//上一页 } else { this.hl1.NavigateUrl = ""; this.hl2.NavigateUrl = ""; } if (curPage < pageCount) { this.hl3.NavigateUrl = "?pg=" + (curPage + 1 ) ;//下一页 this.hl4.NavigateUrl = "?pg=" + pageCount ;//尾页 } else { this.hl3.NavigateUrl = ""; this.hl4.NavigateUrl = ""; } }}
[此贴子已经被作者于2007-4-21 22:44:16编辑过]