获取 asp:Repeater 中某些页面控件的值
在我的 asp.net 页面上,我有几个 DropDownList。 我也有一个复读机。
在 ItemDataBound 事件中,我想获取这些 DropDownLists 的值,以更改 Repeater 中的数据。这些 DropDownList 的 SelectedValue 为空。 但是在ItemDataBound之后,执行Page_Load。在那里我可以获得这些 DropDownLists 的值。
有没有办法在执行 ItemDataBound 时获取值。
谢谢!
菲利普
On my asp.net page, I have several DropDownLists.
I also have a Repeater.
In the ItemDataBound event I want to get the value of these DropDownLists, to change the data in the Repeater. The SelectedValue of these DropDownLists is empty.
But after the ItemDataBound, the Page_Load is executed. There I can get the value of these DropDownLists.
Is there a solution to get the value when the ItemDataBound is executed.
thanks!
Filip
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在 Page.Load 事件中对这些下拉列表进行数据绑定。有很多 Web 控件可以在加载生命周期期间获取其状态或其他详细信息(我很久以前就遇到过此类问题)。
注意:当我说“State”时,我不是在谈论 ViewState。为什么不在加载事件之后进行数据绑定呢?
You need to data-bind these drop-down lists in the Page.Load event.There're a lot of web controls that get their state or other details during load life-cycle (I had these kind of problems long time ago).
NOTE: When I say "State" I'm not talking about ViewState.And why don't you do that data-bind after the load event?
您可以在页面 PreInit 事件中获取下拉列表的选定值吗?如果是这样,请将它们存储在视图状态中,并在转发器的项目数据绑定事件期间从视图状态中检索它们。
如果这不起作用,请尝试将选定的索引更改事件添加到每个下拉列表中。当下拉列表更改时,设置一个视图状态变量,您可以在中继器的项目数据绑定事件期间检索该变量。如果您在页面加载期间要设置下拉列表的值(例如从数据库读取时),请使用这些值直接设置适当的视图状态变量。
Can you get the drop down lists' selected values in the page PreInit event? If so, store them in view state and retrieve them from view state during the repeater's item data bound event.
If that doesn't work, try adding a selected index changed event to each drop down. When the drop downs change, set a view state variable that you can retrieve during the repeater's item data bound event. If you have values to which you are setting the drop downs during page load, such as when reading from a database, use those values to directly set the appropriate view state variables.