DataPager 列出的内容不会超过第二页

发布于 2024-12-29 17:12:28 字数 3728 浏览 1 评论 0原文

DataPager 有一些奇怪的行为。

因此,为了解决问题,我有一个带有信息的 DataPagerReapeater 。我有一个 DataPager, 这是我为了一起工作而做的。我有 3 个页面,但是 DataPager 有一些奇怪的行为。

当我在第一页上单击“下一步”时,它会转到第二页,一切都很好。当我再次单击“下一步”时,它会进行回发,但不会移至第三页。最后一个和第一个也很好用。

但是,当我在第二页上并单击“下一步”时,它不会移动到第三页,而是停留在第二页上。同样,如果我手动单击第三页并单击上一页,它会转到第一页。

我真的不明白为什么。

这是 DataPager

<asp:DataPager ID="DataPager1" PagedControlID="ReapeaterCSGator" PageSize="5" 
        runat="server" onprerender="DataPager1_PreRender">
    <fields>
            <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True"  FirstPageText="<< First"
            ShowNextPageButton="False" ShowPreviousPageButton="False" />
        <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="False"  FirstPageText="< Previous"
            ShowNextPageButton="False" ShowPreviousPageButton="True" />
        <asp:NumericPagerField />
        <asp:NextPreviousPagerField ButtonType="Link" ShowLastPageButton="False"  LastPageText="Next >"
            ShowNextPageButton="True" ShowPreviousPageButton="False" />
        <asp:NextPreviousPagerField ButtonType="Link" ShowLastPageButton="True"  LastPageText="Last >>"
            ShowNextPageButton="False" ShowPreviousPageButton="False" />
    </fields>
</asp:DataPager>

这是我在 PreRender 上执行的代码:

protected override void OnPreRender(EventArgs e)
{
    base.OnPreRender(e);

    IEnumerable<CollaborativeSpace> listCS = LoadCollaborativeSpaces();
    // Binding the repeater with the list of documents
    ReapeaterCSGator.DataSource = listCS;
    ReapeaterCSGator.DataBind();

}

所以,行为真的很奇怪,我不知道问题是什么。

还有其他人遇到过这样的问题吗?

更新:这是加载方法以及我在那里的内容:

        ResultPerPages = GetResultsPerPage();
        DataPager2.PageSize = ResultPerPages;
        DataPager1.PageSize = ResultPerPages;
        //We initialize the pager repeater with the same value
        ReapeaterCSGator.SetPageProperties(0, ResultPerPages, false);
        //We add an handler on item data bound event for sub repeater
        ReapeaterCSGator.ItemDataBound += ReapeaterCSGator_ItemDataBound;
        //If the user is not post backing
        if (!IsPostBack)
        {
            //We add choices on drop down list "Results per page"
            foreach (int choice in NbResultsChoices)
            {
                NbResultsPerPage.Items.Add(new ListItem(choice + " results per page", choice.ToString(CultureInfo.InvariantCulture)));
            }
            //We get collaborative spaces from Sharepoint list
            //IEnumerable<CollaborativeSpace> listCS = LoadCollaborativeSpaces();
            //// Binding the repeater with the list of documents
            //ReapeaterCSGator.DataSource = listCS;

更新2: 以下是 SetPageProperties() 背后的代码,

 public void SetPageProperties(int startRowIndex, int maximumRows, bool databind)
    {
        ViewState["_startRowIndex"] =startRowIndex;
        ViewState["_maximumRows"] = maximumRows;
        if (TotalRows > -1)
        {
            if (TotalRowCountAvailable != null)
            {
                TotalRowCountAvailable(this, new PageEventArgs((int)ViewState["_startRowIndex"], (int)ViewState["_maximumRows"], TotalRows));
            }
        }
    }

该组件在此处使用: http://www.codeproject.com/Articles/45163/Extend-Repeater-to-support-DataPager

问题已解决,似乎 datapagerrrepeater没有以正确的方式实施,现在我找到了可以修复它的来源。无论如何,感谢您的帮助

DataPager has some strange behavior.

So to situate the problem, I have a DataPagerReapeater with information. And I have a DataPager,
which I made to work together. I have 3 pages, but DataPager has some strange behavior.

When I'm on the first page and I click next it goes to 2nd, everything is fine. When I click next again it does a postback but doesnt move to the 3rd page. Last and first also works fine.

But when I'm on the second page and I click next it will not move to the third page, but stays on the second. Same if I manually click on the third page and click previous, it goes to the first page.

I really dont understand why.

Here is the DataPager:

<asp:DataPager ID="DataPager1" PagedControlID="ReapeaterCSGator" PageSize="5" 
        runat="server" onprerender="DataPager1_PreRender">
    <fields>
            <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True"  FirstPageText="<< First"
            ShowNextPageButton="False" ShowPreviousPageButton="False" />
        <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="False"  FirstPageText="< Previous"
            ShowNextPageButton="False" ShowPreviousPageButton="True" />
        <asp:NumericPagerField />
        <asp:NextPreviousPagerField ButtonType="Link" ShowLastPageButton="False"  LastPageText="Next >"
            ShowNextPageButton="True" ShowPreviousPageButton="False" />
        <asp:NextPreviousPagerField ButtonType="Link" ShowLastPageButton="True"  LastPageText="Last >>"
            ShowNextPageButton="False" ShowPreviousPageButton="False" />
    </fields>
</asp:DataPager>

Here is the code which I execute on PreRender:

protected override void OnPreRender(EventArgs e)
{
    base.OnPreRender(e);

    IEnumerable<CollaborativeSpace> listCS = LoadCollaborativeSpaces();
    // Binding the repeater with the list of documents
    ReapeaterCSGator.DataSource = listCS;
    ReapeaterCSGator.DataBind();

}

So, the behavior is really strange and I have no idea what the problem could be.

Anyone else confronted such an issue?

UPDATE: Here is on load method and what i have in there:

        ResultPerPages = GetResultsPerPage();
        DataPager2.PageSize = ResultPerPages;
        DataPager1.PageSize = ResultPerPages;
        //We initialize the pager repeater with the same value
        ReapeaterCSGator.SetPageProperties(0, ResultPerPages, false);
        //We add an handler on item data bound event for sub repeater
        ReapeaterCSGator.ItemDataBound += ReapeaterCSGator_ItemDataBound;
        //If the user is not post backing
        if (!IsPostBack)
        {
            //We add choices on drop down list "Results per page"
            foreach (int choice in NbResultsChoices)
            {
                NbResultsPerPage.Items.Add(new ListItem(choice + " results per page", choice.ToString(CultureInfo.InvariantCulture)));
            }
            //We get collaborative spaces from Sharepoint list
            //IEnumerable<CollaborativeSpace> listCS = LoadCollaborativeSpaces();
            //// Binding the repeater with the list of documents
            //ReapeaterCSGator.DataSource = listCS;

UPDATE 2:
Here is the code behind SetPageProperties()

 public void SetPageProperties(int startRowIndex, int maximumRows, bool databind)
    {
        ViewState["_startRowIndex"] =startRowIndex;
        ViewState["_maximumRows"] = maximumRows;
        if (TotalRows > -1)
        {
            if (TotalRowCountAvailable != null)
            {
                TotalRowCountAvailable(this, new PageEventArgs((int)ViewState["_startRowIndex"], (int)ViewState["_maximumRows"], TotalRows));
            }
        }
    }

That component was used form here: http://www.codeproject.com/Articles/45163/Extend-Repeater-to-support-DataPager

PROBLEM SOLVED, it seems that the datapagerrepeater wasnt implemented the right way, now that i found the sources i could fix it. Thanks anyways for the help

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

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

发布评论

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

评论(1

情深缘浅 2025-01-05 17:12:28

如果我没看错您的加载方法,那么您将在每个 Page_Load 上将转发器重置为第 1 页。

发生的情况是:

  • Page_Load 中,您在 SetPagerProperties() 调用中将中继器重置为第 1 页。
  • 在控制事件调度阶段,数据分页器前进到下一页< strong>相对于第 1 页:
    • 如果您使用“第一个”和“最后一个”以及特定页面,则一切正常,因为它们不是相对更改
    • “下一页”会转到第 1 页之后的页面,这就是您卡在第 2 页上的原因,
    • “上一页”尝试转到 1 之前的页面,因为没有页面,所以它停留在 1 上。

要解决此问题,请停止在每次页面加载时初始化分页器。要么摆脱这个呼叫——我不确定它为什么在那里,我只用它来“重置”中继器,例如在用户单击列标题对列表视图进行排序之后。或者将其移至 if (!IsPostback) 块中。

If I read your load method right, you're resetting the repeater to page 1 on every Page_Load.

What happens is:

  • In Page_Load, you reset the repeater to page 1 in the SetPagerProperties() call
  • During the control event dispatch phase, the datapager is advanced to the next page relative to page 1:
    • if you use "first" and "last" and specific pages, everything works, because they're not relative changes
    • "next" goes to the page after page 1, which is why you're stuck on page 2,
    • "previous" tries to go to the page before 1, since there is none, it stays on 1.

To fix this, stop initialising the pager on every page load. Either get rid of the call – I'm not sure why it's there, I only use it to "reset" the repeater, for example after a user clicks a column header to sort a list view. Or move it into the if (!IsPostback) block.

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