I would like to restrict deletion to new rows that were inserted but as by the Add button. Currently, the code allows users to delete the first record populating the grid view and I would like to prevent this.
Can any one give me an idea?
First form which was initially loaded: I am adding text to text box and later I will click on Add

Second form which will be loaded after clicking
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.
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.

Sam HobbsPosted Jun 3, 2011, 9:09 PM
Alternatively, I think that ADO has a status property for each record that indicates whether a row has been added or updated or whatever; perhaps you can use that to determine if a recoird was added.
Dorababu MekaPosted Jun 3, 2011, 9:27 AM
satheesh kandikondaPosted Jun 3, 2011, 2:24 AM
Suthish NairPosted Jun 3, 2011, 1:37 AM