Jax
Jax

Reputation: 997

How to cancel update in sqldatasource_updating event?

I'm using a gridview and sqldatasource.

I can't find a way to cancel the update the update without closing the row from the edit event. because e.cancel is not available in updating event.

I need to do it in UPDATED not in UPDATING because in updating I can't get some events.

thanks

Upvotes: 1

Views: 1910

Answers (1)

Rab
Rab

Reputation: 35582

you can use e.KeepInEditMode = true; to keep the updated record in edit mode. but you can't cancel updating in updated, because record has already been updated till that. you will to have find another way to do it, with custom coding.

ASPX

<asp:GridView ID="GridView1" runat="server" 
            onrowdatabound="GridView1_RowDataBound" 
            onrowupdated="GridView1_RowUpdated">
</asp:GridView>

CS

protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
 {
            e.KeepInEditMode = true;
 }

in case of sqldatasource

protected void SqlDataSource1_Updated(object sender, SqlDataSourceStatusEventArgs e)
 {
            e.Command.Cancel();
 }

Upvotes: 1

Related Questions