repeater分页实例

//        初始化分页类

PagedDataSource Pgds=new PagedDataSource();
//        获取数据源

   Pgds.DataSource=CreateDataSource().DefaultView;也可以Pgds.DataSource=List<News>();任何数据集都可
//        设置允许分页
   Pgds.AllowPaging=true;
//        每页显示为6行
   Pgds.PageSize=6;
//        显示总共页数,lblTotalPage为lable控件
   lblTotalPage.Text=Pgds.PageCount.ToString();
//        当前页
   int CurrentPage;
//        请求页码为不为null设置当前页,否则为第一页
   if(Request.QueryString["Page"] != null)
   {
    
    CurrentPage = Convert.ToInt32(Request.QueryString["Page"]);
   }

   else
   {

    CurrentPage = 1;
   }
//   当前页所引为页码-1
   Pgds.CurrentPageIndex = CurrentPage - 1;
//   显示当前页码
   lblCurrentPage.Text = CurrentPage.ToString();
//   如果不是第一页,通过参数Page设置上一页为当前页-1,否则不显示连接
   if(!Pgds.IsFirstPage)
   {
    //            Request.CurrentExecutionFilePath为当前请求虚拟路径
    lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage - 1);
   }
//        End If
//   如果不是最后一页,通过参数Page设置下一页为当前页+1,否则不显示连接
   if(!Pgds.IsLastPage)
   {
//    Request.CurrentExecutionFilePath为当前请求虚拟路径
    lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurrentPage + 1);
   }
//   模板绑定数据源  
   Repeater1.DataSource = Pgds;
   Repeater1.DataBind();

posted @   卡萨丁·周  阅读(155)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 通过 API 将Deepseek响应流式内容输出到前端
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗
点击右上角即可分享
微信分享提示