惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
IT之家
IT之家
博客园_首页
量子位
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
博客园 - 聂微东
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
爱范儿
爱范儿
大猫的无限游戏
大猫的无限游戏
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
雷峰网
雷峰网
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
Microsoft Azure Blog
Microsoft Azure Blog
有赞技术团队
有赞技术团队
S
SegmentFault 最新的问题
Engineering at Meta
Engineering at Meta
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

博客园 - 简约旋律

如何做一名优秀的部门经理 viewstate 的工作原理 char与varchar的区别 堂堂正正做人 认认真真做事 笨鸟 节约时间 ASP.NET中的FILE对象总结 当梦想照进现实 (C#) C#中的@符号 数据库事务 读写删文件代码 什么是SQL注入及SQL注入工具 void的使用 导航树扩展 按F5运行时出现目录清单 经典JS收藏 GET POST的使用 关于request的一个问题 一些代码
Repeater/DataList分页方法
简约旋律 · 2007-11-22 · via 博客园 - 简约旋律

关于Repeater和DataList控件分页,我习惯用二种方法实现,其一就是利用PagedDataSource类来实现,相对简单一些,方法一如下:

  public void ListBind()
  {
   myConn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("/data/data.mdb"));
   OleDbDataAdapter myComm=new OleDbDataAdapter("select * from guestbook order by gbdate desc",myConn);
   DataSet ds=new DataSet();
   myComm.Fill(ds,"guestbook");

   PagedDataSource pds=new PagedDataSource();
   pds.DataSource=ds.Tables["guestbook"].DefaultView;
   pds.AllowPaging=true;
   pds.PageSize=8;

   int CurrentPage;
   if(Request.QueryString["Page"]!=null)
    CurrentPage=Convert.ToInt32(Request.QueryString["Page"]);
   else
    CurrentPage=1;
   pds.CurrentPageIndex=CurrentPage-1;
   lblCurrentPage.Text=CurrentPage.ToString();
   lblPageCount.Text=pds.PageCount.ToString();
   if(!pds.IsFirstPage)
   {
    lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath+"?Page="+Convert.ToInt32(CurrentPage-1);
    lnkFirst.NavigateUrl=Request.CurrentExecutionFilePath+"?Page=1";
   }
   if(!pds.IsLastPage)
   {
    lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+"?Page="+Convert.ToInt32(CurrentPage+1);
    lnkLast.NavigateUrl=Request.CurrentExecutionFilePath+"?Page="+pds.PageCount;
   }
   dlstGuestbook.DataSource=pds;
   dlstGuestbook.DataBind();
  }