一位CSDN网友放在下载里的 / /// <summary> /// 分页函数 /// </summary> /// <param name="dtRecord">数据源</param> private void SplitPage(DataTable dtRecord) { string htmlPage = ""; int pageSize = 15; //每页显示记录数 int listStep = 10; //最多显示分页页数 int pages = 1; //当前页,默认显示第一页 int pageCount = 0; //定义总页数 int recordCount = 0; //定义总记录数 int listBegin = 0; //从第几页开始显示分页信息 int listEnd = 0; //分页信息显示到第几页 if (dtRecord == null || dtRecord.Rows.Count == 0) { return; } recordCount = dtRecord.Rows.Count; //确定数据记录要显示的页面数 if(recordCount > 0) { pageCount = recordCount / pageSize; } if(recordCount % pageSize > 0) { pageCount++; } //取得当前页数值,并判断 if(Request["pages"] != null) { pages = Convert.ToInt32(Request["pages"]); } if(pages < 1) { pages = 1; } if(pages > pageCount) { pages = pageCount; } listBegin = pages - listStep / 2; //从第几页开始显示分页信息 if (listBegin < 1) { listBegin = 1; } listEnd = listBegin + listStep - 1; //分页信息显示到第几页 if (listEnd > pageCount) { listEnd = pageCount; listBegin = listEnd - listStep + 1; if (listBegin < 1) { listBegin = 1; } } //确认当前页面的开始记录和终止记录 int recordBegin = pageSize * (pages - 1); int recordEnd = recordBegin + pageSize - 1; if(recordEnd > recordCount - 1) { recordEnd = recordCount - 1; } //显示数据记录 htmlPage = DisplayDataRecord(dtRecord, recordBegin, recordEnd); Response.Write(htmlPage); htmlPage = ""; //显示分页列表 htmlPage += GetPageList(pages, pageCount, listBegin, listEnd); Response.Write(htmlPage); htmlPage = ""; }