Introduction
In this blog, you will learn how to edit, update, and delete in ListView.
First, drag and drop the 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 five columns as: ProductId, ProductName, ProductLocation, ProductQuantity, and ProductPrice.
- Download My Sample.
- Inside that folder, person.sql file will be there. Execute it in your database.
- Change the connection string in web.config file.
Building the Sample
This sample is written by 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
SQL
-
-
- SET ANSI_NULLS ON
- GO
-
- SET QUOTED_IDENTIFIER ON
- GO
-
- SET ANSI_PADDING ON
- GO
-
- CREATE TABLE [dbo].[Product](
- [pk_id] [int] IDENTITY(1,1) NOT NULL,
- [ProductId] [varchar](5) NULL,
- [ProductName] [varchar](50) NULL,
- [ProductPrice] [numeric](8, 2) NULL,
- [ProductLocation] [varchar](25) NULL,
- [ProductQuantity] [varchar](10) NULL,
- PRIMARY KEY CLUSTERED
- (
- [pk_id] ASC
- )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
- ) ON [PRIMARY]
-
- GO
-
- SET ANSI_PADDING OFF
- GO
- select pk_id,ProductId,ProductName,ProductLocation,ProductQuantity,ProductPrice from Product
Description
Note
I have used SQL Server 2008
For this article, we are going to fill ListView by data from the database.
We are going to perform the following operations on data using ListView.
- Add a new record into the database; here data will directly be added to the database table.
- Update Records into the database, using edit link.
- Delete Records using delete link.
C#
- <configuration>
- <connectionStrings>
- <add name="MyConnection"
- connectionString="Data Source=192.169.1.121\sql;Initial Catalog=master;Persist Security Info=True;User ID=Test;Password=Test"
- providerName="System.Data.SqlClient" />
- </connectionStrings>
Source Code Files
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.