Go to DotNetFunda.com
  Welcome, Guest!  
LoginLogin  
{ Submit resources and get monthly gifts !!! }
Submit: Article | Interview Question | Tips | Joke | Question | Link || Search  
 Skip Navigation Links Home > Articles > Inserting, Updating, Deleting and Paging records using ListView controls

All Articles | Post Articles |  Subscribe to RSS

Inserting, Updating, Deleting and Paging records using ListView controls

 Download source file
 Posted on: 1/17/2008 12:53:55 AM by SheoNarayan | Views: 3082 | Category: ASP.NET | Level: Beginner | Print Article |
ASP.NET 3.5 Hosting and MS SQL 2008!
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.

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://dotnetfunda.com/tutorials/tutorial39.aspx ) as the data source of the ListView.

I assume that you have created LINQ to SQL classes by going through http://dotnetfunda.com/tutorials/tutorial39.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 !!!


 Bookmark and Share kick it on DotNetKicks.com

About Sheo Narayan

Experience:6 year(s)
Home page:http://sheonarayan.blogspot.com/
Member since:Tuesday, July 08, 2008
Biography:Throughout 1st in all educational exams.
Major qualifications: HDCS, ADCA, MCA
Location: Hyderabad, India
 Latest post(s) from SheoNarayan

   ◘ Getting selected record key value from ASP.NET Data Controls posted on 10/4/2008 9:27:54 PM
   ◘ Working with Collections - Generic List posted on 10/3/2008 9:54:04 AM
   ◘ Working with Value Types Variables posted on 9/20/2008 10:06:20 PM
   ◘ Working with Collections - ArrayList posted on 9/20/2008 8:04:52 AM
   ◘ Solution of problem having same method name in two interfaces inheriting a class posted on 9/7/2008 8:58:28 AM


Question: Why to use www.dotnetfunda.com google search?
Answer: This search has been especially optimized to search technical articles. You may find to-the-point results in comparison with other search.
Google
About Us | Contact Us | Privacy Policy and Terms of Use | Link Exchange | Members | Go Top
All rights reserved to DotNetFunda.com. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
This site is best viewed with a resolution of 1280x720 (or higher) and Microsoft Internet Explorer 6.0+ or Firefox 2.0+.