My Technical Notes

Tuesday, 21 May 2013

FormView: ChangeMode call must precede Binding of data

What is wrong with the following code:


// wrong
FormView1.DataSource = GetDataSource();
FormView1.DataBind();
FormView1.ChangeMode(FormViewMode.Edit);

?

Well, the answer is that the ChangeMode call must precede the binding of the data:


// correct
FormView1.ChangeMode(FormViewMode.Edit);
FormView1.DataSource = GetDataSource();
FormView1.DataBind();

No comments: