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. Image for the cookie policy date
close icon

Example code for latest version to add, edit and delete to sql database

HI

Can you please supply me with code for the latest version of Gantt to add, edit and delete tasks as all the sample code available seems to be for older versions and not working on the latest version (15.1460.0.41)

THX
Armand

1 Reply

JD Jayakumar Duraisamy Syncfusion Team April 24, 2017 12:26 PM UTC

Hi Armand, 
 
Thanks for contacting Syncfusion support. 
 
We have prepared a Gantt sample to perform add, edit and delete actions with SQL database. It can be achieved by using “ActionComplete” client side event, we will get the updated data as argument and pass the data to the “pageMethod” for perform add, edit & delete operation with SQL table. 
 
Please refer following code snippet, 
<ej:Gantt ID="container" runat="server" 
//… 
ActionComplete="ActionComplete"> </ej:Gantt> 
 
<asp:ScriptManager runat="server" EnablePageMethods="true"></asp:ScriptManager> 
<script type="text/javascript"> 
        function ActionComplete(args) {             
 
            if (args.requestType === 'save' && args.addedRecord) { 
                //Newly Added Record is obtained here , which can be updated to database 
                var ganttRecord = args.addedRecord; 
                if (args.addedRecord.parentItem) 
                    ganttRecord["ParentId"] = ganttRecord.parentItem.taskId; 
 
                PageMethods.AddIt(ganttRecord.item); 
            } else if (args.requestType === 'delete') { 
                var data = args.data; 
                var ganttRec = data.item; 
                PageMethods.DeleteIt(ganttRec); 
 
                if (data.hasChildRecords) { 
                    deleteChildRecords(data); 
                } 
            } 
 
                // To update the database during Outdent,editing,indent,predecessor update operation 
            else if (args.requestType === 'recordUpdate') {                 
                var ganttRec = args.data.item; 
                PageMethods.UpdateIt(ganttRec); 
            } 
 
        } 
[ASPX.cs] 
[WebMethod] 
        public static void AddIt(TaskData record) 
        { 
            Gantt obj = new Gantt(); 
            obj.Add(record); 
        } 
        [WebMethod] 
        public static void UpdateIt(TaskData record) 
        { 
            Gantt obj = new Gantt(); 
            obj.Update(record); 
        } 
        [WebMethod] 
        public static int DeleteIt(TaskData record) 
        { 
            Gantt obj = new Gantt(); 
            obj.Delete(record); 
            return 0; 
        } 
 
We have also prepared a sample using latest version source & dll's for your reference, please find the sample location as below. 
Regards, 
Jayakumar D. 


Loader.
Live Chat Icon For mobile
Up arrow icon