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

Hi good day I would like to see a complete example of treegrid in javascript with connections to SQL databases which have fuciones crud thank you very much

Hi good day
I would like to see a complete example of treegrid in javascript with connections to SQL databases which have fuciones crud

thank you very much

I perform this request because I can not find good documentation on this control

1 Reply

JS Jonesherine Stephen Syncfusion Team September 12, 2016 09:43 AM UTC

Hi Andres, 
Thanks for contacting Syncfusion support 
Query 1 I would like to see a complete example of treegrid in javascript with connections to SQL databases which have functions crud 
Solution: We have prepared the workaround and rendered the TreeGrid with Sql database. 
And by using the “actionComplete” and “endEdit” client side events in TreeGrid we can update the data base during insert, update and delete action.  
Please find the code example below for sever side methods to render the TreeGrid with Sql database 
[aspx.cs] 
      [WebMethod]       
        public static object GetTreeGridData() 
        { 
            List<TaskData> list = new List<TaskData>(); 
            SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);//connectionString 
            con.Open(); 
            using (con) 
            { 
                using (var command = con.CreateCommand()) 
                { 
     command.CommandText = "SELECT Id,Name,StartDate,Duration,ParentId FROM treedata"; 
                    using (var reader = command.ExecuteReader()) 
                    { 
                        var indexOfCol1 = reader.GetOrdinal("Id"); 
                        var indexOfCol2 = reader.GetOrdinal("Name"); 
                        var indexOfCol3 = reader.GetOrdinal("StartDate"); 
                        var indexOfCol4 = reader.GetOrdinal("Duration"); 
                        var indexOfCol5 = reader.GetOrdinal("ParentId"); 
                        while (reader.Read()) 
                        { 
                            TaskData obj = new TaskData(); 
                            obj.Id = reader.GetValue(indexOfCol1).ToString(); 
                            obj.Name = reader.GetValue(indexOfCol2).ToString();                           
                            obj.StartDate = reader.GetValue(indexOfCol3).ToString(); 
                            obj.Duration = reader.GetValue(indexOfCol4).ToString(); 
               obj.ParentId = (reader.GetValue(indexOfCol5).ToString() == "") ? null : reader.GetValue(indexOfCol5).ToString(); 
                            list.Add(obj); 
                        } 
                        reader.Close(); 
                    } 
                } 
                con.Close(); 
 
            } 
            return list; 
        } 
        [WebMethod] 
        public void Update(TaskData Task) 
        { 
             
 
 
            string IDNumber = Task.Id; 
 
            string cmdString = "UPDATE treedata SET Id=@Id, Name=@Name,StartDate=@StartDate,Duration=@Duration WHERE Id = '" + IDNumber + "'"; 
 
            SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);//connectionString 
 
            con.Open(); 
 
            using (SqlCommand sqlCommand = new SqlCommand(cmdString, con)) 
            { 
                sqlCommand.Parameters.AddWithValue("@Name", Task.Name); 
                sqlCommand.Parameters.AddWithValue("@Id", Task.Id); 
                sqlCommand.Parameters.AddWithValue("@StartDate", Task.StartDate); 
                sqlCommand.Parameters.AddWithValue("@Duration", Task.Duration); 
                sqlCommand.ExecuteNonQuery(); 
            } 
            con.Close(); 
         
        } 
        
        public void Add(TaskData Task) 
        { 
 
     string cmdString = "INSERT INTO treedata ([Name],[Id],[StartDate],[ParentId],[Duration])" + "VALUES(@Name,@Id,@StartDate,@ParentId,@Duration)"; 
 
            SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);//connectionString 
            con.Open(); 
            using (SqlCommand sqlCommand = new SqlCommand(cmdString, con)) 
            { 
                sqlCommand.Parameters.AddWithValue("@Name", Task.Name); 
                sqlCommand.Parameters.AddWithValue("@StartDate",Task.StartDate); 
                sqlCommand.Parameters.AddWithValue("@Duration", Task.Duration); 
                sqlCommand.Parameters.AddWithValue("@Id", Task.Id); 
                if (Task.ParentId == null) 
                { 
            sqlCommand.Parameters.AddWithValue("@ParentId", Task.ParentId).Value = ""; 
                } 
                else 
                { 
                    sqlCommand.Parameters.AddWithValue("@ParentId", Task.ParentId); 
                } 
 
                int test = sqlCommand.ExecuteNonQuery(); 
            } 
 
            con.Close();             
        } 
        public void Delete(TaskData Task) 
        { 
            string IDNumber = Task.Id; 
            SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);//connectionString 
            con.Open(); 
  SqlCommand cmd = new SqlCommand("delete from treedata where Id = '" + IDNumber + "'", con); 
            int result = cmd.ExecuteNonQuery(); 
            con.Close();            
        } 
We have also prepared the sample to render the TreeGrid using Sql database with ASP as the code behind. Please find the sample from below location: 
 
Query2: I perform this request because I cannot find good documentation on this control 
Solution: 
We are currently enhancing our online documentation. It will available at the end of October 2016. 
Please let us know if you require further assistance on this.
Regards,
Jone sherine P S
 


Loader.
Live Chat Icon For mobile
Up arrow icon