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
If I read your load method right, you're resetting the repeater to page 1 on every
Page_Load
.What happens is:
Page_Load
, you reset the repeater to page 1 in theSetPagerProperties()
callTo 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.