Access数据库分页显示(实例)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Access数据库分页显示(实例)最终效果如下图所示,样式自己加,只需要写入数据库表就能用。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace QQ.Web.desk
{
public partial class khal : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
theWZTAWZJSKHANBind();
theXUNHUANBind();
}
}
//分页
private void thePageBind()
{
int currengPage; //当前页
int pageNumber; //总页数
int pageSize = 4; //每页显示几条信息
string Strpage = PUB.Utils.RequestQueryString("page");
if (Strpage == "")
{
currengPage = 1;
}
else
{
currengPage = int.Parse(Strpage);
}
er_New PBLL = new er_New();
string strSQL = "";
DataSet ds = new DataSet();
ds = PBLL.GetList(strSQL);
int strPageCount = ds.Tables[0].Rows.Count;//获得总记录数总条数
//总页数
pageNumber = strPageCount / pageSize;//总页数=总记录数除以每页信息数
if (strPageCount % pageSize > 0)//取余,
{
pageNumber += 1;
}
string strwhere = "";
if (currengPage == 1)
{
strwhere = "select top " + pageSize + " * from User_New";
}
else
{
strwhere = "select top " + pageSize + " * from User_New where New_ID not in (select top " + ((currengPage - 1) * pageSize) + " New_ID from User_New)";
}
DataSet dt=new DataSet();
dt=Maticsoft.DBUtility.DbHelperOleDb.Query(strwhere);
RepKHAN.DataSource = dt;
RepKHAN.DataBind();
string strPageShow = ""; //字符串
if (currengPage == 1)
{
strPageShow += "首页";//首页
}
else
{
strPageShow += "<a href=?page=1>首页</a> ";
}
if (currengPage == 1)
{
strPageShow += "上一页";
}
else
{
strPageShow += "<a href=?page=" + (currengPage - 1) + ">上一页</a> ";
}
#region 中间显示页面11个(有自己决定)
if (pageNumber <= 10)
{
for (int i = 1; i <= pageNumber; i++)
{
if (i == currengPage)
{
strPageShow += " " + i + " ";
}
else
{
strPageShow += "<a href=?page=" + i + ">" + i + "</a> ";
}
}
}
else
{
int intstartPage;//起始页
int intOverPage;//最后显示页
intstartPage = currengPage - 5;
intOverPage = currengPage + 4;
if (intstartPage <= 0)
{
intstartPage = 1;
intOverPage = 10;
}
if (intOverPage > pageNumber)
{
intOverPage = pageNumber;
intstartPage = pageNumber - 9;
}
for (int i = intstartPage; i <= intOverPage; i++)
{
if (i == currengPage)
{
strPageShow += " " + i + " ";
}
else
{
strPageShow += "<a href=?page=" + i + ">" + i + "</a> ";
}
}
}
#endregion
if (currengPage == pageNumber)
{
strPageShow += "下一页";
}
else
{
strPageShow += " <a href=?page=" + (currengPage + 1) + ">下一页</a> ";
}
if (currengPage == pageNumber)//
{
strPageShow += " 末页";
}
else
{
strPageShow += " <a href=?page=" + pageNumber + ">末页</a> ";
}
txtpageshow.Text = strPageShow;
}
}
}。