I have a GridView control hooked up to a datasource that I allow row editing on. I use the standard edit/save/delete buttons that point to the Update, Cancel, and edit GridView commands.
I would like to add an additional button, "Next" inline with the save/cancel button. This would function the same as the save button, but would also add an additional row to the grid, and place that row into edit mode. To do this, I've added code to the Updated
event of the GridView, which adds a new record to the db, rebinds the grid, and sets the editindex. This seems work, but the grid does not actually return in edit mode. I stripped out the new record code and simply left the statement to set the editindex, but the grid still will not stay in edit mode.
Is it possible to force the grid to stay in edit mode in this scenario? It appears that unless you set the cancel property of the GridViewUpdatedEventArgs
, the Grid is going to flip to view mode. I don't want to set the cancel property in this case, because I want the GridView to trigger my datasource object to save the record.
If this doesn't work, it appears that I will need to allow the update to occur normally, return to the client, and then send another server request to add the record. I'd prefer not to do it this way, I would like to perform the necessary operations in context of one roundtrip.
Here's what the code (simplified) looks like:
protected void Button1_Click(object sender, EventArgs e)
{
// Works Fine
this.sampleDataSource.Insert();
this.sampleGridView.DataBind();
this.sampleGridView.EditIndex = this.sampleGridView.Rows.Count - 1;
}
protected void sampleGridView_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
// Grid will display new row, but will not be in edit mode
this.sampleDataSource.Insert();
this.sampleGridView.DataBind();
this.sampleGridView.EditIndex = this.sampleGridView.Rows.Count - 1;
}