Test your technical skills online, appear in Virtual Interview and be ready for job!
Twitter Twitter LinkedIn YouTube Google
Be Interview ready ! | Search
Make friends on DotNetFunda.com and expand your network!

Win Prizes

Like us on Facebook
Top Articles Author
Wed, 16-Apr-2014 Authors
All Time Authors

Latest members | More ...

(Statistics delayed by 5 minutes)

Inserting, Updating, Deleting and Paging records using ListView controls

Posted by under ASP.NET category on for Beginner level | Views : 18353 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.

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 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 !!!
Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:

About the Author


Full Name: Sheo Narayan
Member Level: HonoraryPlatinum
Member Status: Microsoft_MVP,Administrator
Member Since: 7/8/2008 6:32:14 PM
Country: India
Regards, Sheo Narayan The Founder http://www.dotnetfunda.com

Microsoft MVP, Author, Writer, Mentor & architecting applications since year 2001. Connect me on http://www.facebook.com/sheo.narayan | https://twitter.com/sheonarayan | http://www.linkedin.com/in/sheonarayan
Login to vote for this post.

Comments or Responses

Login to post response.

Comments / Responses
Select text & click toolbar to format. Formatting appears in viewmode only. HTML Tags are not allowed.
Bold Italic Underline Paragraph Title Code  Link 
 Wait ... Processing ..... please wait.

Comment using Facebook