欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

一个简答的Access下的分页asp.net代码

程序员文章站 2024-03-08 18:30:40
复制代码 代码如下:public void listarticle() { cmsarticle arobj = new cmsarticle(); dataset ds...
复制代码 代码如下:

public void listarticle()
{
cmsarticle arobj = new cmsarticle();
dataset ds = arobj.listarticle();
if (ds != null)
{
pageddatasource pds = new pageddatasource();
pds.datasource = ds.tables[0].defaultview;
pds.allowpaging = true;
pds.pagesize = 1;
pds.currentpageindex = currentpage - 1;

rscount = ds.tables[0].rows.count;
pagecount = pds.pagecount;
pagesize = pds.pagesize;

gvnewlist.datasource = pds;
gvnewlist.databind();


///上下页
double result;
result = rscount / pagesize;
string[] r = new string[2];
r = result.tostring().split('.');
pagecount = convert.toint32(r[0]);

if (result > pagecount)
{
pagecount = pagecount + 1;
}

///上一页和首页
if (!pds.isfirstpage)
{
lnkprev.navigateurl = "?page=" + convert.tostring(currentpage - 1);
//lnkhead.navigateurl ="?page=" + convert.tostring(1);
}

///下一页和末页
if (!pds.islastpage)
{
lnknext.navigateurl = "?page=" + convert.tostring(currentpage + 1);
//lnkend.navigateurl = "?page=" + convert.tostring(rscount);
}
}

listinfolabel.text = "全部共" + rscount + "篇,每页" + pagesize + "篇,当前第" + currentpage + "/" + pagecount + "页";
pageinfoliteral.text = webapp.pagination.show(currentpage, pagecount, 10, "?page=", "");
}