We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Update predecessor after deleting

Thread ID:





118088 Jan 30,2015 04:16 PM UTC Feb 2,2015 01:58 PM UTC ASP.NET Web Forms 1
Tags: Gantt
Otto Moura Machado Filho
Asked On January 30, 2015 04:16 PM UTC


How can I update my predecessor field on database when I delete a row that has a reference in another row. It updates on gantt but don't fire a edit event for exemple, only the "delete event".

Otto Machado.

John Rajaram [Syncfusion]
Replied On February 2, 2015 01:58 PM UTC

Hi Otto,

We can update our predecessor field of the reference rows that connected with deleted task item to the database by retrieving the corresponding updated TaskId and Predecessor values of the rows from the Gantt data source and it can be updated to the database with the help of AJAX POST method in the controller.

Please refer the below code snippets for more details.

Code snippets:

In Index.cshtml:




ClientSideEvents(eve =>







<script type="text/javascript">

     function ActionComplete(args) {


      else if (args.requestType === 'delete') {

               // To delete a Task item

                var ganttRec = args.data.item;


                    type: "POST",

                    url: "/Gantt/Delete",  //Update is Server side method

                    data: ganttRec,

                    dataType: "json",                  


               // To update the predecessors of the reference rows

                if (args.data.predecessor) {

                    var param = [], datalinks,links, j = 0;

                    for (var i = 0; i < args.data.predecessor.length; i++) {

                        if (args.data.predecessor[i].to != args.data.taskId) {

                            var updateId = args.data.predecessor[i].to;

                            for (var k = 0; k < args.model.dataSource.length; k++) {

                                if (updateId == args.model.dataSource[k].TaskId) {

                                    var links = args.model.dataSource[k].Predecessor;

                                    param[j] = {

                                        linkId: updateId,

                                        linkString: links









                    contentType: 'application/json; charset=utf-8',

                    type: "POST",

                    url: "/Gantt/UpdatePredecessors",  //Update is Server side method

                    data: param,

                    dataType: "json",




In GanttController.cs:

public class GanttController : Controller




        public void UpdatePredecessors(List<TaskLinks> Items)


            connectionString = string.Format(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=" + Server.MapPath("App_Data") + @"\GanttDatabase2008.mdf;Integrated Security=True;Connect Timeout=30");


            SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);//connectionString


            for (int i = 0; i < Items.Count; i++)


                int IDNumber = Items[i].LinkId;

                string cmdString = "UPDATE GanttData1 SET Predecessor=@Predecessor WHERE TaskId = '" + IDNumber + "'";

                using (SqlCommand sqlCommand = new SqlCommand(cmdString, con))


                    if (Items[i].LinkString == null)


                        sqlCommand.Parameters.AddWithValue("@Predecessor", Items[i].LinkString).Value = "";




                        sqlCommand.Parameters.AddWithValue("@Predecessor", Items[i].LinkString);










Please let us know if you require further assistance on this.

John. R


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon