This is a migrated thread and some comments may be shown as answers.

Calling codebehind after automatic update

6 Answers 20 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Neil N
Top achievements
Rank 1
Veteran
Iron
Neil N asked on 06 Jan 2019, 02:59 PM
How do I execute some server-side code after data has been updated, triggered by the user clicking "Save changes" in an automatic-update batch-editmode grid? I need to manipulate some other controls after a successful update.

6 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 09 Jan 2019, 01:40 PM
Hi Neil,

You can use the dedicated BatchEditCommand event handler or the ItemCommand event handler by checking for this condition:

if (e.CommandName == RadGrid.BatchEditCommandName) { ... }

Here you are a suitable documentation article Batch Editing Server-side API.

Best Regards,
Rumen
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Neil N
Top achievements
Rank 1
Veteran
Iron
answered on 09 Jan 2019, 05:06 PM

Hi Rumen,

Unless I'm missing something (apologies if I am), neither of these options provides what I asked for.

Protected Sub grdSalesReport_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles grdSalesReport.ItemCommand fires for every single change. If twenty rows are changed, the event is fired twenty times.

 

Protected Sub grdSalesReport_BatchEditCommand(sender As Object, e As GridBatchEditingEventArgs) Handles grdSalesReport.BatchEditCommand fires before the update statements are sent to the database. It's an an automatic-update batch-editmode grid as stated above.

I need to run some code after all the updates have been sent.

0
Rumen
Telerik team
answered on 11 Jan 2019, 05:25 PM

The SqlDataSource control has an OnUpdated event which raises the Updated event after the SqlDataSource control has completed an update operation. You can find more on this at MSDN: https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.sqldatasourceview.onupdated?view=netframework-4.7.2.

Best regards,
Rumen
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Neil N
Top achievements
Rank 1
Veteran
Iron
answered on 11 Jan 2019, 07:09 PM

Again, I don't think this is what I'm asking for. From the doc:

Raises the Updated event after the SqlDataSource control has completed an update operation.

What I asked for:

I need to run some code after all the updates have been sent.

0
Accepted
Attila Antal
Telerik team
answered on 16 Jan 2019, 04:07 PM
Hi Neil,

It has become clear that you would like to use an event that fires only once after all the records have been updated. RadGrid has it's DataBound event which fires only when the data is bound to it. Since editing/inserting/updating items requires the grid to rebind, this event would be the perfect one for your scenario. The only problem is that there is no built-in property or method to understand whether a Batch Editing was done or not, but it's very simple to implement.

For example, you can use the BatchEditCommand which is fired once before any update. At this point you can set a flag that will indicate the reason for the postback. Once all the Updates are finished, data with the changes will be bound to Grid again and so the DataBound event fires. You can use this event in combination with the Flag you have set earlier to identify whether it was an update or not and run the desired logic.

bool IsBatchCommand = false;
// Event raised before an actual Update
protected void RadGrid1_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
{
    IsBatchCommand = true;
}
 
// Event raised after every update is done and data is re-bound to Grid
protected void RadGrid1_DataBound(object sender, EventArgs e)
{
    if (IsBatchCommand)
    {
        Label1.Text += "<br />RadGrid1_DataBound";
    }
}

Please let us know if you have any question.

Kind regards,
Attila Antal
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Neil N
Top achievements
Rank 1
Veteran
Iron
answered on 22 Jan 2019, 04:40 PM
This is exactly what I needed.  Thank you very much.
Tags
Grid
Asked by
Neil N
Top achievements
Rank 1
Veteran
Iron
Answers by
Rumen
Telerik team
Neil N
Top achievements
Rank 1
Veteran
Iron
Attila Antal
Telerik team
Share this question
or