How to Solve a Common Problem With Asp.net Formview Defaultstate Property
The ASP.NET FormView WebControl is one of the most useful items you can find in the Microsoft Visual Studio .NET Toolbar, now, although is extremely easy to use, you can make mistakes and walk in circles just because you forgot a simple click, especially when using the DefaultState property.
This property defines the “default” state for the webcontrol after an insert/update/delete operation, that is, the state to wich the control will return after any of those operations are perfomed. So, the property DOES NOT CHANGE the current FormView’s state, to do that use the ChangeState method instead. Check this c# code:
//Sets the default mode after a delete/insert/update operation
FormView1.DefaultMode = FormViewMode.ReadOnly;
//This changes the formview's state
FormView1.ChangeMode(FormViewMode.Insert);
A common problem is when you are linking a FormView to a GridView (to do a master-details), if you notice that the behavior is not what you want; check what you are doing with that property. Setting the default value to “ReadOnly” usually works fine. If you need to “change” the state of the FormView because of your programming logic, try the ChangeState method.
Leonardo is a .NET programmer who likes to share code and ideas with the people around the globe.
He runs the TeKnowMagic Team and offers several games and tools for download from his site.
Article Source: ArticlesBase.com - How to Solve a Common Problem With Asp.net Formview Defaultstate Property