you tell it to cancel from the edit event by calling e.Cancel = true. This allows you to cancel edit mode when the edit was successful or leave it in edit mode if the edit failed.
protected void gvTest_Edit(Object sender, GridViewEditEventArgs e)
{
gvTest.EditIndex = e.NewEditIndex;
Response.Write("Editing...");
if (successful)
{
e.Cancel = true;
}
else
{
// Display a message or whatever you want to do
// to let the user know there was a problem
}
}
Cancel is a property of GridViewEditEventArgs, you can get more information on it from MSDN or by googling it I'm sure. When you are using a datasource control, such as SqlDatasource or EntityDatasource, the Cancel property is set automatically. When you are manually binding the gridview control then you have to tell it when to Cancel.
If you need to cancel within the CancelEdit event you need to do the same thing, set e.Cancel = true.