Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 7993 |  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: 11908 | Category: ASP.NET | Level: Beginner | Points: 150 red flag

Advertisements

Advertisements
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


Advertisements

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

To generate Edit, Delete, Update and Select buttons automatically in the GridView, we can follow this approach.

When we consume business objects in UI the logic can become pretty complex. Activities like setting the business object value, getting the object value and setting the user interface from the object value. We can minimize the complexity of UI interaction with business object using mediator pattern.

In this article we will see how we can use the Chart Control in asp.net. Today we will be inserting,searching and deleting data in the Application and checking how the results are shown in Graphical View.

In earlier articles, we learnt how to create, read, expire cookies. In this article we are going to learn how to limit the scope of the cookies to a particular folder of the website or particular sub-domain of the website.

In this article we will be looking into how uploading the powerpoint and then binding its link to GridView to download can be achieved.

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 find 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. | 6/20/2013 1:11:19 AM