编辑后如何刷新 FormView?

发布于 2024-12-19 15:44:24 字数 529 浏览 4 评论 0原文

我正在使用 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 技术交流群。

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

发布评论

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

评论(2

注定孤独终老 2024-12-26 15:44:24

您需要再次进行数据绑定。

void FormView_ItemInserted(Object sender, FormViewInsertedEventArgs e)
{
  Gridview.Databind();
}

You need to databind again.

void FormView_ItemInserted(Object sender, FormViewInsertedEventArgs e)
{
  Gridview.Databind();
}
朦胧时间 2024-12-26 15:44:24

当父控件被修改时,您需要触发子控件进行数据绑定。

我发现执行此操作的最可靠位置是在父控件的 DataBound 事件中。编辑成功后,会调用此事件,因为控件需要重新绑定到编辑后的数据。

这是我的一些实际代码的片段,我在其中做了类似的事情。其中,我有一个名为 QuestionGroupResutls 的控件,该控件在名为 QuestionResults 的控件中具有子记录。

void QuestionGroupResults_DataBound(object sender, EventArgs e)
{
    QuestionGroupsEditingDetailsView1.DataBind();
    QuestionResults.DataBind();

}

我在 Page_Load 中有这个,但是您可以在 asmx 中以声明方式指定它(我只是没有代码示例)。

 QuestionGroupResults.DataBound += new EventHandler(QuestionGroupResults_DataBound);

我不知道你的控件的名称,但你应该能够用你的控件做同样的事情。

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.

void QuestionGroupResults_DataBound(object sender, EventArgs e)
{
    QuestionGroupsEditingDetailsView1.DataBind();
    QuestionResults.DataBind();

}

I have this in Page_Load, but you can specify this declaratively in the asmx (I just don't have a code sample).

 QuestionGroupResults.DataBound += new EventHandler(QuestionGroupResults_DataBound);

I don't know the name of your controls, but you should be able to do the same thing with yours.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文