Database and Connection string
For this article as usual I have used my favorite NorthWind database which you can get by clicking on the link below.
Below is the connection string from the Web.Config file
Below I have a simple GridView ASP.Net GridView control populated from the Customers table of Northwind database. It displays 2 columns Contact Name and City of which city is editable via ASP.Net DropDownList control. The identifier column Customer Id is bind to the DataKeyNames property.
Binding the GridView
Below is the code to Bind the GridView control with data.
Below is the screenshot of GridView with data
Editing the GridView Row
The below events handle the GridView Row Edit and Cancel Edit Events
Binding the DropDownList
The DropDownList has to be bind in the RowDataBound event of the ASP.Net GridView control in the following way. I have kept an invisible Label in order to get the previously stored City.
The below screenshot displays the GridView with row being edited
Updating the GridView Row
Finally here’s the code to update the record with the new selected value from the ASP.Net DropDownList control.
You can download the full source code of this article in C# and VB.Net using the download link provided below.DropdownlistinEditItemTemplateGridView.zip