_pagecount = (_recordCount % _pagesize==0) ? (_recordCount / _pagesize) : (_recordCount / _pagesize + 1);
.....
int _page;
int _pagesize = 10;
int _pagecount;
int _recordcount;
System.Text.StringBuilder sbPager = new System.Text.StringBuilder(); //用来显示分页
//在.aspx页中调用,用以显示分页代码
public string getPager()
{
return sbPager.ToString();
}
//计算出记录数
_recordcount = 134;
//判断当前页数
private void Page_Load(object sender, System.EventArgs e)
{
if(Request.QueryString["page"]==null)
{
_page = 1;
}
else
{
_page = Int16.Parse(Request.QueryString["page"]);
}
...............
}
//开始填充数据
private void FillList()
{
_recordcount= BLL.MessageBLL.getListCount(""); //取得总记录数
_pagecount = (_recordcount % _pagesize==0)?(_recordcount/_pagesize):(_recordcount/_pagesize+1); //得到总页数
int _minPage=1;
if(_page!=1)
{
_minPage = (_page-1)*_pagesize + 1;
}
this.repMsgList.DataSource = BLL.MessageBLL.GetList("",_minPage,_pagesize);
this.repMsgList.DataBind();
#region 打印页数
for (int i = 1; i <= _pagecount; i++)
{
if (i == _page)
//如果是当前页,不显示链接
sbPager.Append("<span >" + i.ToString() + "</span> ");
else
{
sbPager.Append("<a href=?page="+i+">" + i + "</a> ");
}
}
sbPager.Append(_recordcount + " Records");
#endregion
}