WCF And ListView Insert Update And Delete Rows In ASP.NET

In this article you will learn how to edit, update and delete in ListView. First drag and drop ListView. In ListView, next open Default.aspx source code. To make a column in Listview use <LayoutTemplate>. Here first I created a table name 'Product' in my database. It contains 5 columns: ProductId, ProductName,ProductLocation,ProductQuantity, and ProductPrice.

Introduction

In this article you will learn how to edit, update and delete in ListView. First drag and drop ListView. In ListView, next open Default.aspx source code. To make a column in Listview use   <LayoutTemplate>.  Here first I created a table name 'Product' in my database. It contains 5 columns: ProductId, ProductName,ProductLocation,ProductQuantity, and ProductPrice.

  1. Download my sample.
  2. Inside that folder person.sql file will be there; execute it in your database. 
  3. Change the connection string in web.config file

Building the Sample

This sample is written using three tier architecture so you have to add references.

UI->BusinessLogic

BusinessLogic->DataAccess back to BL 

BusinessLogic->Commonfunctioon back to BL

BusinessLogic -> UI finally BL return data to UI

  1. /****** Object:  Table [dbo].[Product]    Script Date: 05/31/2013 10:56:27 ******/    
  2. /****** Sathiyamoorthy.S ******/    
  3. SET ANSI_NULLS ON    
  4. GO    
  5.     
  6. SET QUOTED_IDENTIFIER ON    
  7. GO    
  8.     
  9. SET ANSI_PADDING ON    
  10. GO    
  11.     
  12. CREATE TABLE [dbo].[Product](    
  13.     [pk_id] [int] IDENTITY(1,1) NOT NULL,    
  14.     [ProductId] [varchar](5) NULL,    
  15.     [ProductName] [varchar](50) NULL,    
  16.     [ProductPrice] [numeric](8, 2) NULL,    
  17.     [ProductLocation] [varchar](25) NULL,    
  18.     [ProductQuantity] [varchar](10) NULL,    
  19. PRIMARY KEY CLUSTERED     
  20. (    
  21.     [pk_id] ASC    
  22. )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ONON [PRIMARY]    
  23. ON [PRIMARY]    
  24.     
  25. GO    
  26.     
  27. SET ANSI_PADDING OFF    
  28. GO    
  29. select pk_id,ProductId,ProductName,ProductLocation,ProductQuantity,ProductPrice from Product   

ASP.NET

ASP.NET

ASP.NET
 

 

Description

Note
I have used SqlServer 2008.

For this article we are going to fill ListView by data from database.

We are going to perform the following operations on data using ListView:

  1. Add New record into database; here data will directly be added into database table
  2. Update Records into database, using edit link.
  3. Delete Records using delete link

  1. <configuration>    
  2.   <connectionStrings>    
  3.     <add name="MyConnection"    
  4.          connectionString="Data Source=192.169.1.121\sql;Initial Catalog=master;Persist Security Info=True;User ID=Test;Password=Test"    
  5.          providerName="System.Data.SqlClient" />     
  6.   </connectionStrings>   

 

Source Code Files

  • sql
  • jpeg
  • jpeg
  • jpeg
  • jpeg

More Information

Source - http://msdn.microsoft.com/en-us/library/bb398790(v=vs.100).aspx

The ASP.NET ListView control enables you to bind to data items that are returned from a data source and display them. You can display data in pages. You can display items individually, or you can group them.

The ListView control displays data in a format that you define by using templates and styles. It is useful for data in any repeating structure, similar to the DataList and Repeater controls. However, unlike those controls, with the ListView control you can enable users to edit, insert, and delete data, and to sort and page data, all without code.