If your using a formview on a page it might be useful to set the default mode dynamically depending on whether the datasource returns a record or not.
For example I'm using a formview to populate a table - if a record already exists for my criteria I want to edit it, otherwise I want to add a new one.
I could test the datasource directly but I thought it would be neater to actually test the formview itself after it's databound. i.e.
protected void FormView1_DataBinding(object sender, EventArgs e)
if (FormView1.DataItemCount < 1)
FormView1.DefaultMode = FormViewMode.Insert;
FormView1.DefaultMode = FormViewMode.Edit;
Works a treat - I guess there could be lots of ways to achieve this, if anybody has any let me know. But it works for me :0)
Blogged with Flock
Tags: c#, formview, databinding, datasource, defaultmode