Introducing DotNetFunda.com on mobile http://m.dotnetfunda.com ! Be with DotNetFunda.com on the go !
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 7934 |  Welcome, Guest!   Register  Login
Home > Articles > ASP.NET > FormView in Edit, Insert, Readonly mode

FormView in Edit, Insert, Readonly mode

Article posted by Ganeshji on 8/17/2010 | Views: 6197 | Category: ASP.NET | Level: Beginner | Points: 150 red flag


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


If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:1 year(s)
Home page:
Member since:Saturday, July 24, 2010
Level:Starter
Status: [Member]
Biography:
 Responses
Posted by: Akiii | Posted on: 17 Aug 2011 05:39:18 AM | Points: 25

nice overview of the control...

Thanks and Regards
Akiii

Posted by: Ganeshji | Posted on: 17 Aug 2011 11:28:35 AM | Points: 25

Thnx Akii!

>> Write Response - Respond to this post and get points
Related Posts

This Article shows you the creation of customizable portals and pages using the ASP.NET 2.0’s new WebParts controls.

Code review is one of the important activities in any project. Manual code reviews are definitely good and I will say better than automation. But when the project is large manual code reviews have their own limitations. FXCOP is one of the legendary tools which help us automate code reviews. This article will discuss some basics of FXCOP and then concentrate mainly on how we can add custom rules in FXCOP.

In this Article you can Know how to get a Multiple selected values using CheckBox

It’s new world of software reusability. Gone are the days when we need to build things from scratch. One of the most needed functionality is the logging utility. Every software project needs a logging utility. To make your own logging utility is a big project by itself. In this tutorial we will quickly run through how you can use Microsoft logging application blocks to log messages and activities.

System.DirectoryServices namespace can be used to access Internet Information Service(IIS). You can create, delete and change the properties of web servers, virtual directories, directories and files. Also you can invoke IIS methods.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2012 8:30:14 AM