Search
Sponsor
deccansoft ad
Winners

Win Prizes

Social Presence
Twitter Twitter LinkedIn YouTube Google

Like us on Facebook
Advertisements
Top Articles Author
Mon, 22-Sep-2014 Authors
All Time Authors
Sourav.Kayal
39750
SheoNarayan
38050
Niladri.biswas
33350

Latest members | More ...


(Statistics delayed by 5 minutes)
Ads
 Article

FormView in Edit, Insert, Readonly mode

Ganeshji
Posted by under ASP.NET category on for Beginner level | Points: 150 | Views : 16540 red flag
If you found plagiarised (copied) or inappropriate content,
please let us know the original source along with your correct email id (to communicate) for further action.
In this article, i have tried to explain three different modes of the FormView control.


Introduction


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:


Templates

Description

ItemTemplate

Displays bound data in read-only mode.

EditItemTemplate

Allows a user to modify an existing record.

InsertItemTemplate

Allows a user to add a new record.

FooterTemplate

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

HeaderTemplate

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

EmptyDataTemplate

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

PagerTemplate

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" .




EditItemTemplate




InsertItemTemplate





ItemTemplate





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.





Conclusion


Enjoy Reading!



Reference

http:// www. vkinfotek. com/detailsview/detailsview-vs-fomview-control.html
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.formview.aspx


Page copy protected against web site content infringement by Copyscape
About the Author

Ganeshji

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.
Found interesting? Add this to:


Comments or Responses

Posted by: Akiii on: 8/17/2011 | Points: 25

nice overview of the control...

Thanks and Regards
Akiii

Posted by: Ganeshji on: 8/17/2011 | Points: 25

Thnx Akii!

Login to post response

Comment using Facebook(Author doesn't get notification)