Reputation: 21
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?
Upvotes: 2
Views: 5782
Reputation: 2321
You need to databind again.
void FormView_ItemInserted(Object sender, FormViewInsertedEventArgs e)
{
Gridview.Databind();
}
Upvotes: 4
Reputation: 73564
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.
Upvotes: 1