Editing and updating in gridview in asp net
In this example, I am going to retrieve values from categories table of Northwind database. Drag a Grid View into the Web Form and assign Data Key Names property with the primary key column i.e. In the gdview_Row Editing and gdview_Row Deleting event, we have used the below code to retrieve categoryid from datakey of Grid View, int catid = int.
In a previous post we saw how easy is to bind data to a Grid View control, without using a build in Data Sources.
Use the same modal popup extender which we use for adding new users and same html will be used, when we go for updating the record we will keep Id in hidden field and pass to update the rocord.We will always open modal popup from code behind so we can execute all the necessary methods.First of all we will create a table Users CREATE TABLE [Users]( [User ID] [int] IDENTITY(100,1) NOT NULL, [User Name] [varchar](50) NULL, [Address] [varchar](100) NULL, [City] [varchar](50) NULL, [State] [varchar](50) NULL, CONSTRAINT [PK_Users] PRIMARY KEY ([User ID]) ) Some points which you need to understand, in Modal Popup Extender we used Behavior ID which will help to find the modal popup and close it.The above piece of code will also do the same as label in Item Template and Textbox in the Edit Item Template.By default all the boundfields will be trasferred as Textboxes in Edit Mode.