SiteMap  | About    

ASP.NET GridView Editing

The GridView control provides many built-in capabilities that allow the user to sort, update, delete, select, and page through items in the control.


The GridView allows editing on a row-by-row basis. An editable GridView contains an additional column with an Edit button in each row. When the end user clicks on an Edit button that row becomes editable, causing the Edit button to change to Update and Cancel buttons and the other columns to become TextBoxes. The end user can then update one or more column values and click Update to save their changes. To enable editing, set the AutoGenerateEditButton property to true and specify the DataKeyNames as the primary key of your table.

Download Database

In this article I have used Microsoft's Pubs database for sample data. You can download it free from the following link.


Before you start to create Edit functionality on GridView in your asp file, you should create a ConnectionString in your web.Config File. Double click the web.config file on the right hand side of the Visual Studio and add the following connectionstring code in that file.

web.config file

Web.Config File


<?xml version="1.0"?>
	<add name="SQLDbConnection"
	 connectionString="Server=Your-Server-Name; Database=pubs; User Id=sa; password= your-passoword"
	 providerName="System.Data.SqlClient" />

The following program shows how to update gridview values from an ASP.NET application



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
	<title>Untitled Page</title>
	<form id="form1" runat="server">
	<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AutoGenerateEditButton="true"
	AllowSorting="True" DataSourceID="SqlDataSource1" AllowPaging="True" DataKeyNames="stor_id">
		<asp:BoundField ReadOnly="True" HeaderText="stor_id"
		DataField="stor_id" SortExpression="stor_id"></asp:BoundField>
		<asp:BoundField HeaderText="stor_name" DataField="stor_name"
		<asp:BoundField HeaderText="stor_address" DataField="stor_address"
		<asp:BoundField HeaderText="city" DataField="city"
		<asp:BoundField HeaderText="state" DataField="state"
		<asp:BoundField HeaderText="zip" DataField="zip"
	<asp:SqlDataSource ID="SqlDataSource1" runat="server"
	ConnectionString="<%$ ConnectionStrings:SQLDbConnection %>"
	SelectCommand="select * from stores"
	UpdateCommand="UPDATE [stores] SET [stor_name] = @stor_name , [stor_address] =  @stor_address , [city] = @city , [state]=@state , [zip]=@zip
	WHERE [stor_id] = @stor_id" >
	<asp:Parameter Type="String" Name="stor_name"></asp:Parameter>
	<asp:Parameter Type="String" Name="stor_address"></asp:Parameter>
	<asp:Parameter Type="String" Name="city"></asp:Parameter>
	<asp:Parameter Type="String" Name="state"></asp:Parameter>
	<asp:Parameter Type="String" Name="zip"></asp:Parameter>
</html> (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.