DataPager 列出的内容不会超过第二页
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我没看错您的加载方法,那么您将在每个
Page_Load
上将转发器重置为第 1 页。发生的情况是:
Page_Load
中,您在SetPagerProperties()
调用中将中继器重置为第 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:
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.