public void UpdatePaging(PagerContext pagerContext, PageContext pageContext) { PagerContext = pagerContext; PageContext = pageContext; DataBindChildren(); Visible = PageContext != null && PageContext.PageCount > 1; }
public PageContext CreatePageContext(PagerContext pagerContext, long firstItemIndex, long lastItemIndex, long itemCount, long pageIndex, long pageCount) { return(new PageContext( firstItemIndex: firstItemIndex, lastItemIndex: lastItemIndex, itemCount: itemCount, pageIndex: pageIndex, pageCount: pageCount, pageLinks: GeneratePageLinks(pagerContext, firstItemIndex, lastItemIndex, itemCount, pageIndex).ToArray())); }
void SqlDataSource_Selected(object sender, SqlDataSourceStatusEventArgs e) { var pagerContext = new PagerContext(EffectivePageSizes, EffectivePageSize, EffectiveDisplayedPageSelectorCount); var pageContext = _Pager.CreatePageContext( pagerContext, firstItemIndex: Math.Max(0, e.Command.Parameters["@_paging_firstRowIndex"].Value <long>() - 1), // Convert from 1-based to 0-based lastItemIndex: Math.Max(0, e.Command.Parameters["@_paging_lastRowIndex"].Value <long>() - 1), // Convert from 1-based to 0-based itemCount: e.Command.Parameters["@_paging_rowCount"].Value <long>(), pageIndex: Math.Max(0, e.Command.Parameters["@_paging_pageIndex"].Value <long>() - 1), // Convert from 1-based to 0-based pageCount: e.Command.Parameters["@_paging_pageCount"].Value <long>()); _UpperPagingControls.UpdatePaging(pagerContext, pageContext); _LowerPagingControls.UpdatePaging(pagerContext, pageContext); }
public IEnumerable <PageLink> GeneratePageLinks(PagerContext pagerContext, long firstItemIndex, long lastItemIndex, long itemCount, long pageIndex) { yield return(new PageLink( display: "«", itemIndex: 0, enabled: firstItemIndex > 0)); yield return(new PageLink( display: "‹", itemIndex: firstItemIndex / pagerContext.PageSize * pagerContext.PageSize - pagerContext.PageSize, enabled: firstItemIndex > 0)); var halfPageSelectors = pagerContext.DisplayedPageSelectorCount / 2; var directPageLinks = Enumerable .Range(-pagerContext.DisplayedPageSelectorCount, pagerContext.DisplayedPageSelectorCount * 2) // Take the range of page selectors negative and positive .Select(index => index * pagerContext.PageSize + firstItemIndex) // Map to item indices relative to the current page .Where(itemIndex => itemIndex >= 0) // Keep item indicies within allowed range .Where(itemIndex => itemIndex < itemCount) // Keep item indicies within allowed range .Select(itemIndex => new { itemIndex, pageIndex = itemIndex / pagerContext.PageSize, // Generate a page number from the item number }) .Where(page => page.pageIndex >= pageIndex - halfPageSelectors) // Ensure that if there a full amount of page .Where(page => page.pageIndex <= pageIndex + halfPageSelectors || pageIndex < halfPageSelectors) // selectors are always shown, even at the ends .Take(pagerContext.DisplayedPageSelectorCount); foreach (var page in directPageLinks) { yield return(new PageLink( display: (page.pageIndex + 1).ToString(), itemIndex: page.itemIndex, enabled: page.pageIndex != pageIndex, current: page.pageIndex == pageIndex)); } yield return(new PageLink( display: "›", itemIndex: firstItemIndex / pagerContext.PageSize * pagerContext.PageSize + pagerContext.PageSize, enabled: lastItemIndex < itemCount - 1)); yield return(new PageLink( display: "»", itemIndex: itemCount / pagerContext.PageSize * pagerContext.PageSize, enabled: lastItemIndex < itemCount - 1)); }