FormView in Edit, Insert, Readonly mode

Posted by in ASP.NET category on for Beginner level | Points: 150 | Views : 29941 red flag

In this article, i have tried to explain three different modes of the FormView control.


FormView Control enables us to display a single record in a browser, from a data source. It allows you to edit, delete, and insert records.

Difference between FormView and DetailsView Control

The DetailsView control uses a tabular layout where each field of the record is displayed  as a row of its own. Whereas, the FormsView control uses a template to display a single record at a time.

The FormView control can be customized by adding templates that allow the user to view or modify the data displayed by the control.

Here, I am going to explain 7 templates of the FormView:




Displays bound data in read-only mode.


Allows a user to modify an existing record.


Allows a user to add a new record.


Displays the contents of the footer row in the footer portion of the FormView table.


Displays the contents of the header row in the header portion of the FormView table.


Displays the contents of the empty data row. Usually it contains contents to alert the user that the data source is empty.


Content for the Pager row is defined here.

By using the DefaultMode property, we can edit and update the records in a FormView control. By default, the FormView control returns to read-only mode. There are 3 different mode values:
1. Edit
2. Insert
3. Read-Only

ReadOnly Mode

Let me start with ReadOnly mode.

Here, in the following figure, i have simply uploaded a record in a table tblFlower.

Below given figure shows successful uploading information.

Now, this table shows the records  inserted in a table.

Now, i want to show you, how to fetch all the records in my FormView control.  Actually, FormView control is present in the Data Tab. Try to drag it in your Design page.

After dragging in your Design page, the control looks like below given figure.

To make a connection with the table, i have used here SqlDataSource which is also present in the Data Tab.

After dragging into the Design page, SqlDataSource looks like below given figure.

Now, I need to configure it. That is I have to make connection with the respective DataSource. For this, I need to click at the smart tag of the SqlDataSource control and click on Configure DataSource. After this, I have to choose  respective datasource.

After proper configuration of the SqlDataSource, I need to connect the FormView control with the SqlDataSource. And for this , click on the smart tag of the FormView and  select SqlDataDataSource1.

In order to apply Paging effect in my FormView control, I have to check the Enable Paging checkbox.

Output showing you the third record.

Edit Mode

Now, let me explain you the Edit mode.

In order to update the records in a FormView, I need to specifically set the DefaultMode="Edit" .




Select and Update statements in the SqlDataSource Control

Output before update

Output after update

Output showing the Paging effect in case of updation

Insert Mode

In order to insert records in a FormView, I need to specifically set the DefaultMode="Insert"

Insert statement in SqlDataSource Control

Output before Insert

I have entered the details in the respective TextBoxes and then clicked on the Insert Button. The record is saved in the tblExample table.

Table showing inserted record

The following table tblExample displays the currently inserted data.


Enjoy Reading!


http:// www. vkinfotek. com/detailsview/detailsview-vs-fomview-control.html

Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: Zinnia Sarkar
Member Level:
Member Status: Member
Member Since: 7/24/2010 12:50:40 PM
Country: India
Regards, Ganeshji

Login to vote for this post.

Comments or Responses

Posted by: Akiii on: 8/17/2011 | Points: 25
nice overview of the control...

Thanks and Regards
Posted by: Ganeshji on: 8/17/2011 | Points: 25
Thnx Akii!

Login to post response

Comment using Facebook(Author doesn't get notification)