如何强制ListView控件以编程方式显示第一页 [英] How to force ListView to show first page programmatically
问题描述
我有一个分页ASP.NET ListView控件。所示过滤的数据,这可以通过一个形式来控制。当过滤器形式的变化,我创建了一个新的查询,并执行的DataBind。
I have a paged ASP.NET ListView. The data shown is filtered, which can be controlled by a form. When the filter form changes, I create a new query, and perform a DataBind.
问题然而,当我去到下一个页面,并设置一个过滤器,ListView控件显示无数据返回。这是不奇怪的,因为应用的筛选后,只有一个数据的页面。
The problem however, when I go to the next page, and set a filter, the ListView shows "No data was returned". That is not weird, because after the filter is applied, there is only one page of data.
所以,我想要做的就是重新寻呼机。那是一个正确的解决问题的方法?而这样做我怎么做呢?
So what I want to do is reset the pager. Is that a correct solution to the problem? And how do I do that?
推荐答案
我在加载处理程序使用这个技巧。它会不会重置寻呼机,如果结果项目数是相同的,但页面索引将仍然有效,所以我可以忍受现在。
I use this hack in my Load handler. It'll not reset the pager if the number of result items is the same, but the page index will still be valid so I can live with that for now.
if (IsPostBack)
{
DataPager pgr = MyListView.FindControl("MyPager") as DataPager;
if (pgr != null && MyListView.Items.Count != pgr.TotalRowCount)
{
pgr.SetPageProperties(0, pgr.MaximumRows, false);
}
}
这篇关于如何强制ListView控件以编程方式显示第一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!