Check this example
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
table
{
border: 1px solid #ccc;
}
table th
{
background-color: #F7F7F7;
color: #333;
font-weight: bold;
}
table th, table td
{
padding: 5px;
border-color: #ccc;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1"
DataKeyNames="CustomerId" ShowFooter="true" OnRowDataBound = "OnRowDataBound">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
<asp:BoundField DataField="Country" HeaderText="Country" ItemStyle-Width="150" />
<asp:CommandField ButtonType="Link" ShowEditButton="true" ShowDeleteButton="true"
ItemStyle-Width="100" />
</Columns>
</asp:GridView>
<table border="1" cellpadding="0" cellspacing="0" style = "border-collapse:collapse">
<tr>
<td style="width: 150px">
Name
</td>
<td style="width: 150px">
Country
</td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtName" runat="server" Width = "140" />
</td>
<td>
<asp:TextBox ID="txtCountry" runat="server" Width = "140" />
</td>
<td>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="Insert" />
</td>
</tr>
</table>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:constr %>"
InsertCommand="INSERT INTO Customers VALUES (@Name, @Country)" SelectCommand="SELECT * FROM Customers"
UpdateCommand="UPDATE Customers SET Name = @Name, Country = @Country WHERE CustomerId = @CustomerId"
DeleteCommand="DELETE FROM Customers WHERE CustomerId = @CustomerId">
<InsertParameters>
<asp:ControlParameter Name = "Name" ControlID = "txtName" Type = "String" />
<asp:ControlParameter Name = "Country" ControlID = "txtCountry" Type = "String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="CustomerId" Type="Int32" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Country" Type="String" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="CustomerId" Type="Int32" />
</DeleteParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
Code
protected void Insert(object sender, EventArgs e)
{
SqlDataSource1.Insert();
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
(e.Row.Cells[2].Controls[2] as LinkButton).Attributes["onclick"] = "return confirm('Do you want to delete this row?');";
}
}
Database
CREATE TABLE [dbo].[Customers](
[CustomerId] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](100) NOT NULL,
[Country] [varchar](50) NOT NULL,
CONSTRAINT [PK_Customers] PRIMARY KEY CLUSTERED
(
[CustomerId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO