编辑后如何刷新 FormView?
我正在使用 FormView
从数据库中选择公司。此 FormView
绑定到 ObjectDataSource
,而 ObjectDataSource
又绑定到 DropDownList
。当用户从 DropDownList
中选择一家公司时,FormView
中将填充与该公司相关的信息(AutoPostBack
在 上启用) DropDownList
提供动态记录更改)。我的 FormView
支持插入、更新和删除功能,这三个功能都可以使用。
我的问题如下:在 FormView
中编辑记录后,该记录成功更改,但是它完全从屏幕上删除。只有当我从 DropDownList
中选择一家新公司后,记录才会重新显示在 FormView
中。
有谁知道这里可能存在什么问题吗?
I am using a FormView
to select companies from a database. This FormView
is bound to an ObjectDataSource
, which is bound to a DropDownList
. When a user selects a company from the DropDownList
, the FormView
is populated with information pertaining to the company (AutoPostBack
is enabled on the DropDownList
to provide dynamic record changing). My FormView
supports insert, update, and delete functions, of which all three work.
My problem is as follows: After I edit a record in the FormView
, the record successfully changes, however, it is completely removed from the screen. Only after I select a new company from my DropDownList
will a record re-display in the FormView
.
Does anyone have an idea as to what may be the issue here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要再次进行数据绑定。
You need to databind again.
当父控件被修改时,您需要触发子控件进行数据绑定。
我发现执行此操作的最可靠位置是在父控件的 DataBound 事件中。编辑成功后,会调用此事件,因为控件需要重新绑定到编辑后的数据。
这是我的一些实际代码的片段,我在其中做了类似的事情。其中,我有一个名为 QuestionGroupResutls 的控件,该控件在名为 QuestionResults 的控件中具有子记录。
我在 Page_Load 中有这个,但是您可以在 asmx 中以声明方式指定它(我只是没有代码示例)。
我不知道你的控件的名称,但你应该能够用你的控件做同样的事情。
You need to trigger the child control to be databound when the parent control has been modified.
I've found that the most reliable palce to do this is in the parent control's DataBound event. After a successful edit, this event is called, because the control needs to re-bind to the edited data.
Here's a snippet from some actual code of mine where I do something similar. In it, I have a control called QuestionGroupResutls that has child records in a control called QuestionResults.
I have this in Page_Load, but you can specify this declaratively in the asmx (I just don't have a code sample).
I don't know the name of your controls, but you should be able to do the same thing with yours.