コード例 #1
0
        public void UpdatePaging(PagerContext pagerContext, PageContext pageContext)
        {
            PagerContext = pagerContext;
            PageContext  = pageContext;
            DataBindChildren();

            Visible = PageContext != null && PageContext.PageCount > 1;
        }
コード例 #2
0
ファイル: Pager.cs プロジェクト: vijayamazon/CaniGold.Store
 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()));
 }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: Pager.cs プロジェクト: vijayamazon/CaniGold.Store
        public IEnumerable <PageLink> GeneratePageLinks(PagerContext pagerContext, long firstItemIndex, long lastItemIndex, long itemCount, long pageIndex)
        {
            yield return(new PageLink(
                             display: "&laquo;",
                             itemIndex: 0,
                             enabled: firstItemIndex > 0));

            yield return(new PageLink(
                             display: "&lsaquo;",
                             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: "&rsaquo;",
                             itemIndex: firstItemIndex / pagerContext.PageSize * pagerContext.PageSize + pagerContext.PageSize,
                             enabled: lastItemIndex < itemCount - 1));

            yield return(new PageLink(
                             display: "&raquo;",
                             itemIndex: itemCount / pagerContext.PageSize * pagerContext.PageSize,
                             enabled: lastItemIndex < itemCount - 1));
        }