我有一個包含中繼器的用戶控件,它的datasouce是使用包含從代碼中的查詢返回的數據的IEnumerable對象設置的。中繼器具有分頁功能,併爲每個頁面顯示自定義數量的記錄。如何在IQueryable中使用Skip()和Take()
我不希望每次用戶單擊下一個按鈕時都加載所有數據,以查看中繼器中記錄的下一頁。我如何使它成爲IQueryable並使用Skip()和Take()僅顯示該頁面所需的記錄?
我有以下代碼:
//Code that assigns query to repeater data source
DataSet = QueryGoesHere.ToArray(); // returns IEnumerable
repeater.DataSource = DataSet;
repeater.DataBind();
//Code that creates PagedDataSource - how can I update this to make it display only the records that are needed for the currently displayed page?
objPds = new PagedDataSource();
objPds.DataSource = DataSource
objPds.AllowPaging = true;
objPds.PageSize = 5;
objPds.CurrentPageIndex = CurrentPage;
lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() + " of " + objPds.PageCount.ToString();