2012-01-30 60 views
1

DataPagerが異常な動作をします。DataPagerは2ページ目以降の一覧を表示しません

問題を解決するために、私は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(); 

} 

ので、行動は本当に奇妙であると私は、問題が何ができるかわかりません。

誰もがこのような問題に直面しましたか?そのコンポーネントは、ここでフォームを使用した

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)); 
      } 
     } 
    } 

SetPageProperties()の背後にあるコードは、ここ :

UPDATE:ここ負荷法にあり、私はそこにある:

 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 :http://www.codeproject.com/Articles/45163/Extend-Repeater-to-support-DataPager

問題が解決しました。datapagerrepeaterが正しい方法で実装されていなかったようです。 修理する。とにかく助けてくれてありがとう

+0

page.ispostbackをチェックしましたか? –

+0

投稿する前にあなたの投稿のスペルミスなどを確認してください=) – jadarnel27

+0

私は何か間違ったスペルミスを見つけませんでした! load_methodを使って投稿を更新しました – Alnedru

答えて

1

ロードメソッドを正しく読んだら、リピータをすべてPage_Loadのページ1にリセットします。

で何が起こるか:

Page_Load
  • 、あなたがコントロールイベントディスパッチ・フェーズでSetPagerProperties()コール
  • では、1ページをリピータをリセットし、datapagerページに対する次のページに進んでいます1
    • あなたが「最初」と「最後」と特定のページを使用する場合、彼らは「次」の相対的変化
    • じゃないので、すべてが、作品ページ1の後のページに行きます。なぜなら、2ページ目にこだわっているからです。
    • "previous"は1の前のページに移動しようとします。何もないので、1のままです。

すべてのページの負荷にページャを初期化停止、これを修正するには。コールを取り除くかどうかはわかりません。リピーターを「リセット」する場合にのみ使用します。たとえば、ユーザーが列見出しをクリックしてリストビューを並べ替えた後です。または、if (!IsPostback)ブロックに移動します。

+0

はい、そうですが、私が(!ポストバックに)設定しても、今でも同じ問題があります。 datapagerrepeaterは私のものではないカスタムコントロールですが、setPagerPropertiesで常に0が与えられていますが、私はtehreのインデックスを増やす必要があると思います。 – Alnedru

+0

@ user1002583リピータ、 SetPagerProperties()を使って標準の 'asp:DataPager'でページを手動で変更する必要はありません。データページャボタンの1つをクリックすると、ページャは開始行インデックスをどのように増加させるかを決定し、ページングされたコントロールのメソッドを正しく呼び出します。 – millimoose

+0

@ user1002583また、問題がCodeProjectの 'DataPagerRepeater'にある場合、なぜそれを使うのですか?ページングもサポートしている標準[ListView](http://msdn.microsoft.com/en-us/library/ie/bb398790.aspx)を使用するだけのようです。 – millimoose

関連する問題