同一页面上有多个 DataPager
我遇到一个问题,同一页面上有 2 个 DataPager,链接到同一个 ListView。一切工作正常,除了“底部”或第二个寻呼机似乎不起作用。页码已生成,但单击它们没有任何反应。如果我将“底部”寻呼机复制到“顶部”寻呼机上方,则该寻呼机将工作,但其下方的寻呼机则不起作用。似乎只有首先出现的寻呼机才起作用:
<asp:DataPager ID="dpPagerTop" runat="server" PagedControlID="lvOutput" QueryStringField="pageNumber">
<Fields>
<asp:NumericPagerField NextPageText="Next" PreviousPageText="Previous" />
</Fields>
</asp:DataPager>
<asp:DataPager ID="dpPagerBottom" runat="server" PagedControlID="lvOutput" QueryStringField="pageNumber">
<Fields>
<asp:NumericPagerField NextPageText="Next" PreviousPageText="Previous" />
</Fields>
</asp:DataPager>
<asp:ListView ID="lvOutput" runat="server" OnPagePropertiesChanged="lvOutput_PagePropertiesChanged">
<LayoutTemplate>
<asp:PlaceHolder id="itemPlaceholder" runat="server" />
</LayoutTemplate>
<ItemTemplate>
<a href="<%# Eval("Link") %>" title="<%# Eval("Title") %>"><%# Eval("Title") %></a>
</ItemTemplate>
</asp:ListView>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
dpPagerTop.SetPageProperties(Request.QueryString["pageNumber"].ToString(), 25, false);
dpPagerBottom.SetPageProperties(Request.QueryString["pageNumber"].ToString(), 25, false);
lvOutput.DataSource = [datasource];
lvOutput.DataBind();
}
}
protected void lvOutput_PagePropertiesChanged(object sender, EventArgs e)
{
lvOutput.DataBind();
}
更新:
经过更多的闲逛后,我确定如果 SetPageProperties 具有正确的参数,两个寻呼机都可以工作。第一个参数应该是开始结果的编号,第二个参数应该是要显示的结果的数量。但是,我显示的数字错误。我正好有 100 条记录,我想每页显示 25 条结果。如果我硬编码:
dpPagerTop.SetPageProperties(25, 25, true);
dpPagerBottom.SetPageProperties(25, 25, true);
这应该是结果的第二页,结果显示26-50。但是,底部寻呼机不起作用。
现在,如果我硬编码:
dpPagerTop.SetPageProperties(26, 25, true);
dpPagerBottom.SetPageProperties(26, 25, true);
两个寻呼机都按预期工作,但结果数量为 27-51。
谁能重现这个,这让我发疯?!?!?
更新 2:
我想我是通过在绑定到 ListView 之前设置页面属性来使其工作的。
I'm having an issue where I have 2 DataPagers on the same page, linked to the same ListView. Everything works fine, except the "bottom" or 2nd pager doesn't seem to be working. The page numbers are generated, but clicking on them does nothing. If I copy the "bottom" pager above the "top" pager, then that pager will work, but the one below it doesn't. Seems a only the pager that comes first seems to work:
<asp:DataPager ID="dpPagerTop" runat="server" PagedControlID="lvOutput" QueryStringField="pageNumber">
<Fields>
<asp:NumericPagerField NextPageText="Next" PreviousPageText="Previous" />
</Fields>
</asp:DataPager>
<asp:DataPager ID="dpPagerBottom" runat="server" PagedControlID="lvOutput" QueryStringField="pageNumber">
<Fields>
<asp:NumericPagerField NextPageText="Next" PreviousPageText="Previous" />
</Fields>
</asp:DataPager>
<asp:ListView ID="lvOutput" runat="server" OnPagePropertiesChanged="lvOutput_PagePropertiesChanged">
<LayoutTemplate>
<asp:PlaceHolder id="itemPlaceholder" runat="server" />
</LayoutTemplate>
<ItemTemplate>
<a href="<%# Eval("Link") %>" title="<%# Eval("Title") %>"><%# Eval("Title") %></a>
</ItemTemplate>
</asp:ListView>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
dpPagerTop.SetPageProperties(Request.QueryString["pageNumber"].ToString(), 25, false);
dpPagerBottom.SetPageProperties(Request.QueryString["pageNumber"].ToString(), 25, false);
lvOutput.DataSource = [datasource];
lvOutput.DataBind();
}
}
protected void lvOutput_PagePropertiesChanged(object sender, EventArgs e)
{
lvOutput.DataBind();
}
UPDATE:
After fooling around with this some more, I've determined that both pagers will work if SetPageProperties has the correct parameters. The first parameter should be the number to start the results and the second should be number of results to show. However, I am getting the wrong numbers to display. I have exactly 100 records and I want to display 25 results per page. If I hardcode:
dpPagerTop.SetPageProperties(25, 25, true);
dpPagerBottom.SetPageProperties(25, 25, true);
This should be the 2nd page of the results and the results show 26-50. However, the bottom pager doesn't work.
Now, if I hardcode:
dpPagerTop.SetPageProperties(26, 25, true);
dpPagerBottom.SetPageProperties(26, 25, true);
Both pagers work like the should, but the number of results go from 27-51.
Can anyone recreate this, it's driving me nuts?!?!?
UPDATE 2:
I think I got it to work by setting the page properties BEFORE binding to the ListView.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了类似的问题,页面上有两个数据分页器绑定到一个列表视图。数据寻呼机与每个寻呼机不同步 - 因此对顶部和底部寻呼机的更改将使寻呼机无法正常工作。这个方法让他们回到正轨:
I had a similar problem with two datapagers on a page bound to one listview. the datapagers weren't synchronized with each - so changes to the top then bottom pagers would have the appearance of the pager not working. This method put them back on track:
我想我已经弄清楚了。
首先,据我所知,您需要在设置页面属性之前对列表视图进行数据绑定。
其次,我认为您误解了 SetPageProperties 方法的第一个参数。它不设置当前页,它设置该页数据的第一条记录。
这是我正在使用的 HTML
这是后面代码中的代码
希望这会有所帮助
I think I have this figured out.
First from what I can tell you need to databind the listview before you set the page properties.
Secondly, I think you are misunderstanding the first parameter to the SetPageProperties method. It does not set the current page, it sets the first record on this page of data.
Here is the HTML I am using
Here is the code in the code behind
Hope this helps