What you want to see on DotNetFunda.com ?
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 16101 |  Welcome, Guest!   Register  Login
Home > Articles > ASP.NET > Inserting, Updating, Deleting and Paging records using ListView controls

Inserting, Updating, Deleting and Paging records using ListView controls

Article posted by SheoNarayan on 1/17/2008 | Views: 16392 | Category: ASP.NET | Level: Beginner red flag


ListView control is a new control added into ASP.NET 3.5. It enables you to display data in a format specified by you using templates and styles. It is useful for data in any repeating structure just like DataList and Repeater controls. However, unlike those controls ListView control enable you to edit, insert, delete, sort, paginate data without any extra effort.

Download


 Download source code for Inserting, Updating, Deleting and Paging records using ListView controls


In this article, I am going to explain a basic way to work with ListView control. After going through this article, you will be able to add, edit, and delete records using ListView control. In this article I am going to use LinqDataSource (Learn how to work with LinqDataSource control in details http://www.dotnetfunda.com/articles/article39.aspx ) as the data source of the ListView.

I assume that you have created LINQ to SQL classes by going through http://www.dotnetfunda.com/articles/article39.aspx article. Now let’s start working with ListView control.



First create a new .aspx page and go to design view. Go to Data tab of the Toolbox and drag ListView control to your page. Now again go to the Data tab and drag LinqDataSource control to the page. Now configure the LinqDataSource control as described in http://dotnetfunda.com/tutorials/tutorial39.aspx article. Make sure that you have selected Enable Delete, Enable Insert and Enable Update checkbox from the smart tag of the LinqDataSource control as displayed in the picture below.



Now open the smart tag of the ListView control and choose the Data Source as the LinqDataSource as displayed in the picture below.


Now click on Configure ListView … from the smart tag of the Listview. Select Tiled from Layout, Professional from Style and Enable Editing, Enable Inserting, Enable Deleting and Enable Paging from the Options as displayed in the picture below. In the Enable Paging dropdown you may select Next/Previous pager or Numeric pager.



Now Save your files and press F5 to run. You should see an Insert form in your browsers. Just enter few records, try editing, deleting records. Once the number of records will exceed the PageSize of the DataPagers (that will be automatically inserted into ListView when you will select Enable Paging from the Configure ListView dialogue box) First, Previous, Next and Last button at the bottom will be enabled automatically.



You should see ListView something like above picture in your browser provided you have inserted the same records as I do :).

Hope you enjoyed playing with ListView and LinqDataSource control. Do let me know if you have any comments or suggestions. Thanks and Happy Coding !!!

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.

About Sheo Narayan

Experience:8 year(s)
Home page:http://www.snarayan.com
Member since:Tuesday, July 08, 2008
Level:HonoraryPlatinum
Status: [Microsoft_MVP] [Administrator]
Biography:Microsoft MVP, Author, Writer, Mentor & architecting applications since year 2001.

Connect me on Facebook | Twitter | LinkedIn | Blog

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

To perform CRUD operation (create, read, update and delete) operation with GridView, we can follow this approach.

In this article I am describe you. How to set IIS on PC then Host Your Website without Visual studio Installation. If you want in such Client machine’s you don’t install Visual Studio and Host Your Website to try it. It’s a very use full for you.

In this article we shall learn how to generate a menu based on SiteMap file and how to generate Menu from the database.

In this section we will run through basics of LINQ and then see 5 basic LINQ queries which you will always need in your project for queries. While looking at the basics we will also try to learn what problem LINQ solves from the perspective of middle tier business objects.

In this article, we shall learn how to load the user control dynamically.

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. | 5/25/2013 4:38:25 AM