dotnetkicks.com 如何实现他们的 ASP.NET 分页?

发布于 2024-07-12 07:44:42 字数 485 浏览 2 评论 0 原文

我知道 dotnetkicks.com 系统是开源的,所以我可以自己查看代码,但我无法制作了解他们如何进行寻呼。 这很难解释,但如果您访问 dotnetkicks.com,您可以使用其首页上的分页。

我特别感兴趣的是它们如何显示前几页,然后是“...”,然后是最后几页。

它开始是这样的

Prev 1 2 3 4 5 6 ... 355 356 Next

然后如果你点击第 10 页,它会变成这样

Prev 1 2 ... 6 7 8 9 10 11 12 13 14 ... 355 356 Next

It's到目前为止我最喜欢的分页系统,所以我想在我的网站上做同样的事情

I know the dotnetkicks.com system is open source so I can view the code myself but I can't make sense of how they did their paging. It's hard to explain but if you goto dotnetkicks.com you can play with the paging on their front page.

What I am specifically interested in is how they show the first few pages, then "..." and then the last few pages.

It starts off like this

Prev 1 2 3 4 5 6 ... 355 356 Next

Then if you hit page 10 it changes to this

Prev 1 2 ... 6 7 8 9 10 11 12 13 14 ... 355 356 Next

It's by far my favorite paging system so I'd like to do the same thing on my websites

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉墨 2024-07-19 07:44:42

urlrewriting.net 作为 /page/n url 格式。

The Pagination control in the project is fairly straight forward, if you've ever written a paging control. I think what may be confusing you is the use of urlrewriting.net for the /page/n url format.

油饼 2024-07-19 07:44:42

我已经编写了这样一个控件,并且需要一些代码......需要做出很多决定。

public class SimplePagerLinkGenerator : IPagerLinkGenerator
{
    private PagingDisplaySettings _displaySettings;

    public SimplePagerLinkGenerator(PagingDisplaySettings displaySettings)
    {
        this._displaySettings = displaySettings;
    }

    public PageLinkData[] GetPagesLinkData(uint crtPageIndex, uint pageCount, ushort pageSize,
        string urlLinkTemplate)
    {
        int i, crtPage = (int)crtPageIndex, pageCnt = (int)pageCount,
            pgInnerCnt = (int)this._displaySettings.PagesBeforeOrAfterCurrent,
            pgEndCnt = (int)this._displaySettings.PagesShownAtEndingsCount;

        int innerBlockStart = crtPage - pgInnerCnt;
        int innerBlockEnd = crtPage + pgInnerCnt;
        int innerBlockStartNormalized = innerBlockStart < 1 ? 1 : innerBlockStart;
        int innerBlockEndNormalized = innerBlockEnd > pageCount ? pageCnt : innerBlockEnd;

        List<PageLinkData> result = new List<PageLinkData>(2 * pgEndCnt + 3 + 2 * pgInnerCnt);
        for (i = 1; i <= pgEndCnt && i <= pageCount; i++)
            result.Add(new PageLinkData(i, i == crtPage, urlLinkTemplate, pageSize));
        if (i > pageCount)
            return result.ToArray();
        if (innerBlockStart > pgEndCnt + 1)
        {
            result.Add(PageLinkData.Ellipsis);
            for (i = innerBlockStart; i <= innerBlockEndNormalized; i++)
                result.Add(new PageLinkData(i, i == crtPage, urlLinkTemplate, pageSize));
        }
        else
            for (i = pgEndCnt + 1; i <= innerBlockEndNormalized; i++)
                result.Add(new PageLinkData(i, i == crtPage, urlLinkTemplate, pageSize));

        if (innerBlockEnd < pageCount - pgInnerCnt)
        {
            result.Add(PageLinkData.Ellipsis);
            for (i = pageCnt - pgInnerCnt + 1; i <= pageCount; i++)
                result.Add(new PageLinkData(i, i == crtPage, urlLinkTemplate, pageSize));
        }
        else
            for (; i <= pageCount; i++)
                result.Add(new PageLinkData(i, i == crtPage, urlLinkTemplate, pageSize));

        return result.ToArray();
    }

    public PagingDisplaySettings DisplaySettings { get { return this._displaySettings; } }
}

I've written such a control and it took some code... there are plenty decisions to take.

public class SimplePagerLinkGenerator : IPagerLinkGenerator
{
    private PagingDisplaySettings _displaySettings;

    public SimplePagerLinkGenerator(PagingDisplaySettings displaySettings)
    {
        this._displaySettings = displaySettings;
    }

    public PageLinkData[] GetPagesLinkData(uint crtPageIndex, uint pageCount, ushort pageSize,
        string urlLinkTemplate)
    {
        int i, crtPage = (int)crtPageIndex, pageCnt = (int)pageCount,
            pgInnerCnt = (int)this._displaySettings.PagesBeforeOrAfterCurrent,
            pgEndCnt = (int)this._displaySettings.PagesShownAtEndingsCount;

        int innerBlockStart = crtPage - pgInnerCnt;
        int innerBlockEnd = crtPage + pgInnerCnt;
        int innerBlockStartNormalized = innerBlockStart < 1 ? 1 : innerBlockStart;
        int innerBlockEndNormalized = innerBlockEnd > pageCount ? pageCnt : innerBlockEnd;

        List<PageLinkData> result = new List<PageLinkData>(2 * pgEndCnt + 3 + 2 * pgInnerCnt);
        for (i = 1; i <= pgEndCnt && i <= pageCount; i++)
            result.Add(new PageLinkData(i, i == crtPage, urlLinkTemplate, pageSize));
        if (i > pageCount)
            return result.ToArray();
        if (innerBlockStart > pgEndCnt + 1)
        {
            result.Add(PageLinkData.Ellipsis);
            for (i = innerBlockStart; i <= innerBlockEndNormalized; i++)
                result.Add(new PageLinkData(i, i == crtPage, urlLinkTemplate, pageSize));
        }
        else
            for (i = pgEndCnt + 1; i <= innerBlockEndNormalized; i++)
                result.Add(new PageLinkData(i, i == crtPage, urlLinkTemplate, pageSize));

        if (innerBlockEnd < pageCount - pgInnerCnt)
        {
            result.Add(PageLinkData.Ellipsis);
            for (i = pageCnt - pgInnerCnt + 1; i <= pageCount; i++)
                result.Add(new PageLinkData(i, i == crtPage, urlLinkTemplate, pageSize));
        }
        else
            for (; i <= pageCount; i++)
                result.Add(new PageLinkData(i, i == crtPage, urlLinkTemplate, pageSize));

        return result.ToArray();
    }

    public PagingDisplaySettings DisplaySettings { get { return this._displaySettings; } }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文