1

DataPager奇妙な振る舞いがあります。

それで、問題を特定するために、私はDataPagerReapeater情報を持っています。そして、私はDataPager一緒に働くために作ったを持っています。3ページありますが、DataPager動作がおかしいです。

最初のページを表示して[次へ]をクリックすると、2番目に移動し、すべて問題ありません。[次へ]をもう一度クリックすると、ポストバックは実行されますが、3ページ目に移動しません。最後と最初も正常に動作します。

しかし、2ページ目にいて[次へ]をクリックすると、3ページ目には移動せず、2ページ目に留まります。同じように、手動で3番目のページをクリックして前をクリックすると、最初のページに移動します。

理由がよくわかりません。

これが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

問題は解決しました。datapagerrepeaterが正しい方法で実装されていなかったようです。修正できるソースが見つかったので、とにかく助けてくれてありがとう

4

1 に答える 1

1

私があなたのロード方法を正しく読んだ場合、あなたはリピーターを毎回1ページにリセットしていますPage_Load

何が起こるか:

  • で、呼び出しPage_Loadでリピーターをページ1にリセットしますSetPagerProperties()
  • 制御イベントディスパッチフェーズ中に、データページャーはページ1に関連する次のページに進みます。
    • 「最初」と「最後」の特定のページを使用すると、相対的な変更ではないため、すべてが機能します
    • 「次へ」は1ページ目以降のページに移動します。そのため、2ページ目でスタックします。
    • 「previous」は1より前のページに移動しようとしますが、ページがないため、1のままになります。

これを修正するには、ページが読み込まれるたびにページャーの初期化を停止します。呼び出しを取り除くか、なぜそこにあるのかわかりません。たとえば、ユーザーが列ヘッダーをクリックしてリストビューを並べ替えた後など、リピーターを「リセット」するためにのみ使用します。または、if (!IsPostback)ブロックに移動します。

于 2012-01-30T17:00:15.013 に答える