Many times, we find ourselves developing a formview, with quite a long template (item, edititem and insertitem templates). The Idea here is to include the insert and edit item templates into one user control, and then the item template into another user control. this way, we dramatically reduce the amount of code in the form, and also, get a better grip on the business logic asked for in the form.
We will start with a very simple example. To make things simple, we'll have a Clients table, with three fields. we'll use the SQLDataSource, For binding with the formview, and stored procedures.
Here's the database table :
Here is the data entry user control :
Code Behind (notice the use of properties to access the data entry controls) :
Here's the formview :
notice how the user control is implemented, in both the EditItemTemplate and the InsertItemTemplate, using properties to access the textboxes. this way we don't have validation code and customizations inside our formview.
and the SqlDataSource :
Simplicity, encapsulation, and seperation of concern, make things much easier to maintain.
here's the full code download. the database is included in the appdata folder, a simple view in browser code to the default.aspx will run the sample.
UserControl In Fromview Sample Code in C#.rar
UserControl In Formview Sample Code in C#.zip
Comments are welcome.