为ASP.net Repeater控件进行分页,具有显示接下来10页的功能

时间:2012-01-24 06:08:31

标签: c# asp.net paging

我正在使用分页功能进行转发器控制,我修改了一个取自以下链接的脚本

http://www.dotnetfunda.com/articles/article456-custom-seo-friendly-paging-with-aspnet-repeater-or-datalist-control-.aspx

我已经在某种程度上对其进行了修改,并且工作正常 现在,分页显示为

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10

分页功能正常工作但我需要修改脚本,以便一旦用户点击下一个10个链接以及上一个和第一个上一个功能,它将显示前5页和下一个5页

基于上述情况的示例

首先 - 上一页 1 | 2 | 3 | 4 | 5 Next5 - 上次

如果我点击Next5链接,那么它应该显示

首先 - 5Previous 6 | 7 | 8 | 9 | 10 下一步 - 上次

下面是代码函数和我的存储过程

private string GetPagingDone(int thisPageNo, int totalCount, int pageSize, string pageName, int LangID, string extraQstringToAdd)
{
    int pageno = 0;
    int start = 0;
    int loop = totalCount / pageSize;
    int ilimit = 5;
    int remainder = totalCount % pageSize;
    StringBuilder strB = new StringBuilder("", 500);
    for (int i = 0; i < loop; i++)
    {
        pageno = i + 1;
        if (pageno.Equals(thisPageNo))
            strB.Append(pageno + "&nbsp; ");
        else
            strB.Append("<a href=\"" + pageName + "?start=" + start + "&page=" + pageno  +"&PageID=" + Request["PageId"] + "&Language=" + Request["Language"] + "\">" + pageno + "</a>  ");
        if (i + 1 == loop)
        { strB.Append("  "); }
        else 
        { strB.Append(" | "); }
        start += pageSize;
    }
    if (remainder > 0)
    {
        pageno++;
        if (pageno.Equals(thisPageNo))
            strB.Append("" + pageno + "&nbsp; ");
        else
            strB.Append("<a href=\"" + pageName + "?start=" + start + "&page=" + pageno + "&PageID=" + Request["PageId"] + "&Language=" + Request["Language"] + "\">" + pageno + "</a>  ");
    }

    return strB.ToString() + "";
}

ALTER PROCEDURE [dbo].[usp_ArticleListPaging]
        @startRowIndex int,
        @pageSize int,
        @LangID int,
        @totalCount int output
    AS
    BEGIN
        SET NOCOUNT ON;
        SET @totalCount = 0
        SET @startRowIndex = @startRowIndex + 1
        BEGIN
           SELECT * FROM ( Select art_Articles.*, ROW_NUMBER() OVER (ORDER BY art_Articles.ArticlePublishDate DESC) as RowNum
           FROM art_Articles WHERE art_Articles.ArticleActive = 1 AND art_Articles.ArticleVisible = 1 AND LanguageID =@LangID) as ArticleList
           WHERE RowNum BETWEEN @startRowIndex AND (@startRowIndex + @pageSize) - 1 ORDER BY ArticlePublishDate DESC
           SELECT @totalCount = Count(ArticleID) FROM art_Articles WHERE art_Articles.ArticleActive  = 1 AND art_Articles.ArticleVisible = 1 AND LanguageID =@LangID
        END
    END

我必须修改相同的代码才能使用此功能。我尝试了几个小时,但无法做到这一点。任何帮助都非常感谢

我不确定为什么我会因为提出这样的问题而被给予

1 个答案:

答案 0 :(得分:1)

这里有一个示例,它将转发器扩展为与另一个称为“DataPager”的内置控件一起工作,该控件应该可以随心所欲。

http://www.codeproject.com/Articles/45163/Extend-Repeater-to-support-DataPager

另一个 http://www.dot4pro.com/extend-repeater-support-datapager.html

有关如何使用它的一些示例 http://www.c-sharpcorner.com/uploadfile/nipuntomar/datapager-in-Asp-Net-3-5/