For demonstration I have created a database (named Database.mdf) in which we have a table named tbl_Employee.
I've a sample below, the Grid View Template is bound to Category Name.
This will trigger the Grid View Row Editing, Row Deleting and Row Updating events respectively.
To trigger the Row Command event you need to set the On Row Command property of your Grid View control.
Inside the template field, we place an item template for displaying records from the database at runtime.
Other templates used here are Edit Item Template and Footer Template. CREATE PROCEDURE [dbo].[employee_pro] ( @empid as int=0, @name as varchar(50)='', @address as varchar(50)='', @designation as varchar(50)='', @status as varchar(50)='' ) AS BEGIN SET NOCOUNT ON; if(@status = 'Display') begin Select * from employee end else if(@status = 'Add') begin Insert into employee(name,address,designation,createtime) values (@name,@address,@designation,getdate()) end else if(@status = 'Update') begin Update employee set [email protected], [email protected],[email protected] where [email protected] end else if(@status = 'Delete') begin Delete from employee where [email protected] end ENDStored cs using System; using System.
In this tutorial I will show you how you can create an editable Grid View control for administrators to modify database records directly into the Grid View control.In the above code, I set two properties Show Edit Button and Show Cancel Button of Command Field.These properties will automatically render Edit, Update and Cancel buttons inside Grid View column.Now I will show you the C# code behind file of the above ASP.NET page that will handle different Grid View events to provide complete editing functionality.