<div>
Qualitifaction :<asp:TextBox ID="txtdata" runat="server"></asp:TextBox>
Year :<asp:TextBox ID="txtyear" runat="server"></asp:TextBox>
<br />
<asp:GridView ID="gvdynamic" runat="server" OnRowEditing="gvdynamic_RowEditing" OnRowCancelingEdit="gvdynamic_RowCancelingEdit"
OnRowUpdating="gvdynamic_RowUpdating" Width="439px">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnedit" CommandName="EDIT" runat="server" Text="EDIT" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="btnupdate" CommandName="Update" runat="server" Text="Update" />
<asp:Button ID="btnCancel" CommandName="Cancel" runat="server" Text="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Button ID="btnadd" runat="server" Text="Add" OnClick="btnadd_Click" />
</div>
public partial class gridview2 : System.Web.UI.Page
{
DataTable dt;
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
dt = new DataTable();
MakeTable();
}
else
dt = (DataTable)ViewState["dt"];
ViewState["dt"] = dt;
protected void MakeTable()
dt.Columns.Add("ID").AutoIncrement = true;
dt.Columns.Add("Qalification");
dt.Columns.Add("Year");
protected void AddRows()
DataRow dr = dt.NewRow();
dr["Qalification"] = txtdata.Text; //Qualification textbox
dr["Year"] = txtyear.Text;//Year textbox
dt.Rows.Add(dr);
protected void btnadd_Click(object sender, EventArgs e)
AddRows();
gvdynamic.DataSource = dt;
gvdynamic.DataBind();
protected void gvdynamic_RowEditing(object sender, GridViewEditEventArgs e)
gvdynamic.EditIndex = e.NewEditIndex;
protected void gvdynamic_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
gvdynamic.EditIndex = -1;
protected void gvdynamic_RowUpdating(object sender, GridViewUpdateEventArgs e)
GridViewRow row = (GridViewRow)gvdynamic.Rows[e.RowIndex];
int Id = Convert.ToInt32(((TextBox)row.Cells[1].Controls[0]).Text);
string Qualification = ((TextBox)row.Cells[2].Controls[0]).Text;
string year = ((TextBox)row.Cells[3].Controls[0]).Text;
DataRow[] datarow = dt.Select("ID='" + Id + "'");
dt.Rows[Id].BeginEdit();
dt.Rows[Id]["Qalification"] = Qualification;
dt.Rows[Id]["Year"] = year;
dt.Rows[Id].EndEdit();
dt.AcceptChanges();