Problem to save in object RadTree nodes values

3 posts, 0 answers
  1. Hans van Rijnswoud
    Hans van Rijnswoud avatar
    72 posts
    Member since:
    Sep 2008

    Posted 14 Oct 2008 Link to this post

    Hi,

    I created a RadTree with BO and it's working perfect.
    When I want to safe the eventualy change in my Database via BO I have a problem and sinds yesterday it is impossible for me to find the solution on your website.

    I create the RadTree like this :

    var categories = new Categories(); 
                    List<Categories> listCategories = categories.GetAllByLanguageId(_languageId); 
                    if (listCategories.Count > 0) 
                    { 
                         
                        RadTreeView1.DataTextField = "Name"
                        RadTreeView1.DataFieldID = "CategorieId"
                        RadTreeView1.DataFieldParentID = "CategorieParentId"
     
                        RadTreeView1.DataSource = listCategories; 
                        RadTreeView1.DataBind(); 
     
                        RadTreeView1.Nodes.Insert(0, MainNode); 
                        // bool disabled duplicate function 
                        isTreeAlreadyExist = true
                    }



    No problem. The result is perfect.

    The problem is if I want to save the change.
    I use the code from your website but the value of each node are empty

    IList<RadTreeNode> allNodes = RadTreeView1.GetAllNodes(); 
     
                try 
                { 
                    for (int i = 0; i < allNodes.Count; i++) 
                    { 
                         
                        var node = (RadTreeNode) allNodes[i]; 
                        if (int.Parse(node.Value) > -2) 
                        { 
     
                            int parentId = allNodes.IndexOf(node.ParentNode); 
                            int categorieId = 0; 
     
                            if (int.Parse(node.Value) > -1) 
                            { 
                                categorieId = int.Parse(node.Value); 
                            } 
     
                            var categorie = new Categories(categorieId); 
                            categorie.Name = node.Text; 
                            categorie.CultureId = cultureId; 
     
                            if (parentId > -1) 
                            { 
                                categorie.CategorieParentId = parentId; 
                            } 
     
                            categorie.CategorieId = categorie.AddUpdate(); 
                        } 
                    } 

    I don't very like this method to save the tree but this is the only way that i found.
    Any idee why is always the value of the node empty.
    Is in the binding the DataFieldId not the value of the nodes???

    Thanks for your help.

    Yves.



  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 14 Oct 2008 Link to this post

    Hello Edwin Blom,

    The DataFieldID property does not set the Value property of the nodes. You should use the DataValueField property for that purpose:

    RadTreeView1.DataTextField = "Name";  
    RadTreeView1.DataFieldID = "CategorieId";  
    RadTreeView1.DataValueField = "CategorieId";  
    RadTreeView1.DataFieldParentID = "CategorieParentId";  


    Regards,
    Albert
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Hans van Rijnswoud
    Hans van Rijnswoud avatar
    72 posts
    Member since:
    Sep 2008

    Posted 21 Oct 2008 Link to this post

    Hi Albert,

    Sorry for my laat answer but your answer is perfect.
    Thanks you for your quick reaction.

    Regards,
Back to Top