列表视图 + DataPager 控件不维护状态
我有一个 ListView
控件和一个应用于它的 DataPager
控件(DataPager
'PagedControlID
设置为 <代码>ListView'ID
)。
碰巧我以这种方式将 ListView
绑定到我的数据源(一个数组):
protected void Page_Load(object sender, EventArgs e) {
if (!this.IsPostBack) {
MyType[] x = ...; /* Returns an array of MyType */
this.MyLV_ListView.DataSource = x;
this.MyLV_ListView.DataBind();
}
}
我启动并转到页面,它页面!但是当我选择另一个页面时,所有内容都是空的,我的意思是有一定数量或条目,但重复区域是空的。
如果我去掉回发条件,就可以了!
protected void Page_Load(object sender, EventArgs e) {
MyType[] x = ...; /* Returns an array of MyType */
this.MyLV_ListView.DataSource = x;
this.MyLV_ListView.DataBind();
}
这是为什么呢? 我无法再次加载所有内容,这是我真正想避免的事情......
谢谢
注意:甚至在两个 ListView
中将 EnableViewState
设置为 true
> 和 DataPager
不会影响任何内容。
I have a ListView
control and a DataPager
control applied to it (the DataPager
'PagedControlID
is set to the ListView
'ID
).
It happens that I bind the ListView
to a datasource of mine (an array) in this way:
protected void Page_Load(object sender, EventArgs e) {
if (!this.IsPostBack) {
MyType[] x = ...; /* Returns an array of MyType */
this.MyLV_ListView.DataSource = x;
this.MyLV_ListView.DataBind();
}
}
I start and go to the page, it pages! but when I select another page everything is empty, I mean there are a certain number or entries, but repeated regions are empty.
If I remove the post back condition, it is ok!
protected void Page_Load(object sender, EventArgs e) {
MyType[] x = ...; /* Returns an array of MyType */
this.MyLV_ListView.DataSource = x;
this.MyLV_ListView.DataBind();
}
Why is this?
I cannot load everything again, it is something I would really like to avoid....
Thankyou
NOTE: Even setting EnableViewState
to true
in both ListView
and DataPager
does not affect anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下这篇博客文章: ASP.NET DataPager 在第一次回发后不进行分页
您还可以尝试以下几项操作:
在 OnPreRender 事件期间进行数据绑定
尝试处理ListView的PagePropertiesChanged事件
Take a look at this blog post: ASP.NET DataPager not paging after first PostBack
Here are a couple more things you can try:
Databind during the OnPreRender event
Try handling the ListView's PagePropertiesChanged event