You need to add the EditItemTemplate in the GridView.
HTML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowEditing="GridView1_OnRowEditing"
OnRowUpdating="GridView1_OnRowUpdating">
<Columns>
<asp:TemplateField HeaderText="Employee Id">
<ItemTemplate>
<asp:Label ID="lblEmployeeId" Text='<%# Eval("EmployeeId") %>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEmployeeId" Text='<%# Eval("EmployeeId") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="First Name">
<ItemTemplate>
<asp:Label ID="lblFirstName" Text='<%# Eval("FirstName") %>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtFirstName" Text='<%# Eval("FirstName") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Last Name">
<ItemTemplate>
<asp:Label ID="lblLastName" Text='<%# Eval("LastName") %>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtLastName" Text='<%# Eval("LastName") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<table width="100%" cellpadding="2" cellspacing="2">
<tr>
<th>
Title
</th>
<th>
Title of Courtesy
</th>
<th>
Birth Date
</th>
</tr>
<tr>
<td>
<asp:Label ID="lblTitle" runat="server" Text='<%#Eval("Title") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblTitleOfCourtesy" runat="server" Text='<%#Eval("TitleOfCourtesy") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblBirthDate" runat="server" Text='<%#Eval("BirthDate") %>'></asp:Label>
</td>
</tr>
<tr>
<th>
Hire Date
</th>
<th>
Home Phone
</th>
<th>
City
</th>
</tr>
<tr>
<td>
<asp:Label ID="lblHireDate" runat="server" Text='<%#Eval("HireDate") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblHomePhone" runat="server" Text='<%#Eval("HomePhone") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblCity" runat="server" Text='<%#Eval("City") %>'></asp:Label>
</td>
</tr>
<tr>
<th>
Region
</th>
<th>
Extension
</th>
<th>
Country
</th>
</tr>
<tr>
<td>
<asp:Label ID="lblRegion" runat="server" Text='<%#Eval("Region") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblExtension" runat="server" Text='<%#Eval("Extension") %>'></asp:Label>
</td>
<td>
<asp:Label ID="lblCountry" runat="server" Text='<%#Eval("Country") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<table width="100%" cellpadding="2" cellspacing="2">
<tr>
<th>
Title
</th>
<th>
Title of Courtesy
</th>
<th>
Birth Date
</th>
</tr>
<tr>
<td>
<asp:TextBox ID="txtTitle" runat="server" Text='<%#Eval("Title") %>'></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtTitleOfCourtesy" runat="server" Text='<%#Eval("TitleOfCourtesy") %>'></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtBirthDate" runat="server" Text='<%#Eval("BirthDate") %>'></asp:TextBox>
</td>
</tr>
<tr>
<th>
Hire Date
</th>
<th>
Home Phone
</th>
<th>
City
</th>
</tr>
<tr>
<td>
<asp:TextBox ID="txtHireDate" runat="server" Text='<%#Eval("HireDate") %>'></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtHomePhone" runat="server" Text='<%#Eval("HomePhone") %>'></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtCity" runat="server" Text='<%#Eval("City") %>'></asp:TextBox>
</td>
</tr>
<tr>
<th>
Region
</th>
<th>
Extension
</th>
<th>
Country
</th>
</tr>
<tr>
<td>
<asp:TextBox ID="txtRegion" runat="server" Text='<%#Eval("Region") %>'></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtExtension" runat="server" Text='<%#Eval("Extension") %>'></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtCountry" runat="server" Text='<%#Eval("Country") %>'></asp:TextBox>
</td>
</tr>
</table>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button Text="Edit" CommandName="Edit" runat="server" />
<asp:Button Text="Update" CommandName="Update" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Namespaces
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
protected void BindGrid()
{
string query = "SELECT EmployeeID,FirstName,LastName,Title,TitleOfCourtesy,BirthDate,HireDate,HomePhone,City,Region,Country,Extension,Notes,Address,PostalCode FROM Employees";
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand(query, con))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
}
protected void GridView1_OnRowEditing(object sender, GridViewEditEventArgs e)
{
this.GridView1.EditIndex = e.NewEditIndex;
this.BindGrid();
}
protected void GridView1_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
{
string employeesId = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtEmployeeId")).Text;
string firstName = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtFirstName")).Text;
string lastName = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtLastName")).Text;
//Likewise find all the TextBox values and update the records
//...
// Write the code for update
//...
Response.Redirect(Request.Url.AbsoluteUri);
}
Screenshot
For edit update delete In GridView please refer this article.