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;
}
else
{
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)
Ta
Dean
Blogged with Flock
Tags: c#, formview, databinding, datasource, defaultmode
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5