ADD
If I click Delete on the red highlighted field, I don't want to delete it, as it is my first record. In this case, I would like delete to remove the later record.
Delete
delete
Here is my code:
protected void btndelete_click(object sender, EventArgs e) { Button lb = (Button)sender; GridViewRow gvRow = (GridViewRow)lb.NamingContainer; int rowID = gvRow.RowIndex + 1; if (ViewState["CurrentTable"] != null) { DataTable dt = (DataTable)ViewState["CurrentTable"]; if (dt.Rows.Count > 1) { if (gvRow.RowIndex < dt.Rows.Count - 1) { //Remove the Selected Row data dt.Rows.Remove(dt.Rows[rowID]); } } //Store the current data in ViewState for future reference ViewState["CurrentTable"] = dt; //Re bind the GridView for the updated data GridView1.DataSource = dt; GridView1.DataBind(); } }
Any help is appreciated.