使用List集合做資料來源,並且使用AspNetPager來分頁

來源:互聯網
上載者:User

標籤:分頁控制項   blog   os   io   使用   ar   資料   art   div   

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();                }

 

使用List集合做資料來源,並且使用AspNetPager來分頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.