Click here to Skip to main content
12,449,910 members (45,881 online)
Click here to Skip to main content
Add your own
alternative version

Stats

21K views
13 bookmarked
Posted

GridView with Add_Update_Delete Operations

, 27 Nov 2007
Rate this:
Please Sign up or sign in to vote.
SoftwareEngineer

Introduction

In .NET 2.0 a very comman and useful tool is provided by MicroSoft to show data in

Hierarchical view.YES it is "GridView".Now It is possible to handle all operations with GridView that use to manipulate database means not only retrive and show record but also ADD , UPDATE,DELETE records as usually we do.

Background

The Code uses fallowing stored procedures.

1-Web_SelectEmployeeDetails

2-Web_EmployeeInsert

3-web_UpdateEmployee

4-web_DeleteEmployee

Web_SelectEmployeeDetails

CREATE PROCEDURE [dbo].[Web_SelectEmployeeDetails]
AS
Select EmployeeID, FirstName,Title,Address,Country,City from Employees
GO

Web_EmployeeInsert

CREATE PROCEDURE dbo.Web_EmployeeInsert

@Name varchar(50),
@LName varchar(50),
@Title nvarchar(25),
@Address nvarchar(50),
@Country varchar(50),
@City varchar(50)
AS

if(@Name='')
select @Name=null

if(@Title='')
select @Title=null

if(@Address='')
select @Address=null

if(@City='')
select @City=null

if(@Country='')
select @Country=null
if(@LName='')
select @LName='HArd-Code'

INSERT INTO Employees(FirstName,LastName,Title,Address,Country,City)
VALUES (@Name,@LName,@Title, @Address, @Country, @City);
SELECT * FROM Employees WHERE (EmployeeID = SCOPE_IDENTITY())
GO

web_UpdateEmployee

CREATE PROCEDURE dbo.web_UpdateEmployee
@EmployeeID int,
@Name varchar(50),
@LName varchar(50),
@Title nvarchar(25),
@Address nvarchar(50),
@Country varchar(50),
@City varchar(50)

AS

UPDATE Employees SET FirstName = @Name,Title = @Title,Address = @Address , Country=@Country, City=@City
WHERE EmployeeID = @EmployeeID

GO

web_DeleteEmployee

CREATE PROCEDURE dbo.web_DeleteEmployee
@EmployeeID int
AS

Delete from Employees WHERE EmployeeID = @EmployeeID

GO

Using the code

The Code uses GridView structure in default.aspx as fallow.

<asp:GridView ID="gvEmployee" runat="server" AutoGenerateColumns="False" ShowFooter="True" DataKeyNames="EmployeeID"
OnRowCommand = "gvEmployee_RowCommand" OnRowCancelingEdit="gvEmployee_RowCancelingEdit" OnRowUpdating="gvEmployee_RowUpdating"
OnRowEditing="gvEmployee_RowEditing" OnRowDeleting="gvEmployee_RowDeleting">

<Columns>
<asp:TemplateField HeaderText="Name">
<EditItemTemplate>
<asp:TextBox ID="txtEditName" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewName" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("FirstName") %>'>

Enjoy Happy Coding Smile | :)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Member 4109048
Web Developer
India India
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160826.1 | Last Updated 27 Nov 2007
Article Copyright 2007 by Member 4109048
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid