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.

In this article I have used SQL SERVER database for sample data.
  

    Create table  tblRecord
    (
      Id int primary key, Name varchar(200),Branch varchar(50)
     )
--Insert some record

 
Before you start to generate 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

  

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
	 <add name="dbSantoshTestConnectionString" 
         connectionString="Data Source=PS-PC\SANTOSH;Initial Catalog=dbSantoshTest;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>



The following source code shows how to update gridview values from an ASP.NET application:-

Girdview.aspx
  

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Girdview.aspx.cs" Inherits="Girdview" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView ID="gvDetail" runat="server" AllowSorting="True" AllowPaging="True" PageSize="3" AutoGenerateColumns="False" AutoGenerateEditButton="True" DataKeyNames="Id" DataSourceID="sqldatasource1" CellPadding="4" ForeColor="#333333" GridLines="None">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
            <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
            <asp:BoundField DataField="Branch" HeaderText="Branch" SortExpression="Branch" />
        </Columns>

        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
        <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
        <SortedAscendingCellStyle BackColor="#FDF5AC" />
        <SortedAscendingHeaderStyle BackColor="#4D0000" />
        <SortedDescendingCellStyle BackColor="#FCF6C0" />
        <SortedDescendingHeaderStyle BackColor="#820000" />

    </asp:GridView>


        <asp:SqlDataSource ID="sqldatasource1" runat="server" ConnectionString="<%$ ConnectionStrings:dbSantoshTestConnectionString %>" SelectCommand="SELECT * FROM [tblRecord]" 
            UpdateCommand="UPDATE [tblRecord] SET [Name] = @Name , [Branch] =  @Branch
	WHERE [Id] = @Id">
    <UpdateParameters>
	<asp:Parameter Type="String" Name="Name"></asp:Parameter>
	<asp:Parameter Type="String" Name="Branch"></asp:Parameter>

	</UpdateParameters>

        </asp:SqlDataSource>

    </div>
    </form>
</body>
</html>