列表视图 + DataPager 控件不维护状态

发布于 2024-11-16 02:58:10 字数 962 浏览 8 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏爱你一生 2024-11-23 02:58:10

看一下这篇博客文章: ASP.NET DataPager 在第一次回发后不进行分页

您还可以尝试以下几项操作:

在 OnPreRender 事件期间进行数据绑定

protected override void OnPreRender(EventArgs e)
{
    this.MyLV_ListView.DataBind();
    base.OnPreRender(e);
}

尝试处理ListView的PagePropertiesChanged事件

MyLV_ListView_PagePropertiesChanged(object sender, EventArgs e)
{
    this.MyLV_ListView.DataSource=someDatasource;
    this.MyLV_ListView.DataBind()
}

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

protected override void OnPreRender(EventArgs e)
{
    this.MyLV_ListView.DataBind();
    base.OnPreRender(e);
}

Try handling the ListView's PagePropertiesChanged event

MyLV_ListView_PagePropertiesChanged(object sender, EventArgs e)
{
    this.MyLV_ListView.DataSource=someDatasource;
    this.MyLV_ListView.DataBind()
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文