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

Problem to save in object RadTree nodes values

2 Answers 102 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Yves
Top achievements
Rank 1
Yves asked on 14 Oct 2008, 01:20 PM
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 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 14 Oct 2008, 01:23 PM
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.
0
Yves
Top achievements
Rank 1
answered on 21 Oct 2008, 05:36 AM
Hi Albert,

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

Regards,
Tags
TreeView
Asked by
Yves
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Yves
Top achievements
Rank 1
Share this question
or