zoukankan      html  css  js  c++  java
  • 使用List集合做数据源,并且使用AspNetPager来分页

    AspNetPager 控件使用时,第一步就要在
    
    if (!IsPostBack)
            {
                  AspNetPager1.RecordCount =数据源记录总数;
    
                //bindData(); //使用url分页,只需在分页事件处理程序中绑定数据即可,无需在Page_Load中绑定,否则会导致数据被绑定两次
            }
    
    第二步就是在 绑定数据源时,指定数据源中开始记录的索引与结束记录的索引,这样就可使用了
    
    void bindData()
    
    {
    
      Repeater1.DataSource = SqlHelper.ExecuteReader(CommandType.StoredProcedure, ConfigurationManager.AppSettings["pagedSPName"],
                new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
                new SqlParameter("@endIndex", AspNetPager1.EndRecordIndex));
            Repeater1.DataBind();
    
    }
    
    问题:如果是用集合来做数据源,怎么办?处理办法利用PagedDataSource做数据源
    
    假设下面例子getdata()返回的是泛型list
    
     void bind()
        {
           this.AspNetPager1.PageSize = 5;//分页控件每页显示记录数
           this.AspNetPager1.RecordCount = getdata().Count;//分页控件要显示数据源的记录总数
          
            PagedDataSource pds = new PagedDataSource ();//数据源分页
            pds.DataSource = getdata();//得到数据源
            pds.AllowPaging = true;//允许分页
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;//当前分页数据源的页面索引
            pds.PageSize = AspNetPager1.PageSize;//分页数据源的每页记录数
            this.Repeater1.DataSource = pds;//指定为控件数据源
            this.Repeater1.DataBind();
         
               }
    
  • 相关阅读:
    Gridview使用CheckBox全选与单选 Version 2
    Repeater控件第前10笔记录高亮显示
    下拉式菜单(DropDownList)连动的选择
    DataList控件显示图片要的是效果
    电容屏、电阻屏基础知识
    SIM300实现GPRS上网
    qt练习7 定时爆炸小游戏
    用 STL vector 来创建二维数组
    sim300_at命令.doc
    QT练习6 label,button创建,点击按键关闭
  • 原文地址:https://www.cnblogs.com/hausthy/p/3958191.html
Copyright © 2011-2022 走看看