在事件中重新绑定Repeater会丢失其控件上的ViewState [英] Rebinding Repeater in an event loses its ViewState on its controls

查看:46
本文介绍了在事件中重新绑定Repeater会丢失其控件上的ViewState的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有一个转发器,其中包含一些前提条件,例如复选框列表和列表框,这些条件决定了转发器带回的数据源.单击一个按钮将对转发器进行数据绑定,效果很好.但是,如果用户决定添加其他内容或删除某些内容,则可以选中/取消选中某些字段,然后再次单击按钮,它将重新绑定转发器并更改显示的内容,但是转发器中所有当前控件的视图状态将丢失.

I have a repeater in my page with some pre-conditions such as a checkbox list and listboxes that dictate what the datasource for the repeater brings back. A button is clicked which will databind the repeater which works fine. However if the user decides they want to add something else in or remove something they can check/uncheck some fields and then hit the button again which will rebind the repeater and change what is displayed, however the viewstate of all the current controls in the repeater will be lost.

不可能将重复器绑定到初始化事件中,因为在页面生命周期的那一刻,复选框列表/列表框值的ViewState不可用,并且这些值是必需的,以便作为参数传递给我的数据源.中继器.

Binding the repeater in the initialization event would not be possible because the ViewState for the checkboxlist/listbox values are not available at that point in the page lifecycle, and those values are required in order to pass as parameters into my datasource for the repeater.

我可以使用哪些选项来保持转发器控件的状态?

What are my options for maintaining the state of my repeater controls?

推荐答案

中继器控件绑定完全重新创建了中继器模板中的所有子控件.因为新的DataBind结果可能(也可能不会)在转发器中包含完全不同的数据.您想在直放站内保持什么样的控件及其状态?也许使用序数html控件并通过Request.Form集合对其进行操作会是更好的方法?

repeater control binding fully recreates all of children controls inside repeater templates. Because new DataBind result may (or may not) contains extremely different data inside repeater. What kind of controls and their state you want to maintain inside repeater? Maybe using ordinal html controls and operating with theirs through Request.Form collection would be a better way?

如果要在应用新的数据绑定之前从转发器保存数据,使其成为最佳位置是Page.PreRender事件.在这种情况下,所有的Page控件都已经重新创建,并且它们的视图状态也已经恢复.因此,您可以通过Repeater.Items集合进行迭代,并逐行保存转发器中的数据.保存所有数据后,您可以根据页面上的当前过滤器值重新绑定转发器控件.

If you want to save data from repeater before applying new databinding, best place for making it is a Page.PreRender event. In this event all Page controls already recreated and their viewstate already restored. So you may iterate by Repeater.Items collection and save data from repeater row by row. And after saving all the data you may rebind repeater controls according current filter values from page.

这篇关于在事件中重新绑定Repeater会丢失其控件上的ViewState的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆