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

[Solved] Problem with programmatically created treeview

2 Answers 159 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 19 Feb 2010, 09:43 AM
Hi,
If I drag a treeview control onto my page and set the DataFieldParentID, I get the treeview correctly displaying with multi-levels of nodes/hierarchy.

However - if I try to create a treeView from my code like this:

            radTreeView.DataTextField = "CategoryName"
            radTreeView.DataValueField = "ID"
            radTreeView.DataFieldParentID = "ParentCategory"
            radTreeView.CheckBoxes = true
            radTreeView.DataSource = myDataSource; 
            radTreeView.DataBind(); 
            
            this.Controls.Add(radTreeView); 
The treeview just displays all the nodes at the same, top level - so there's there's no tree to it. It seems to be ignoring the ParentCategory field that I bound to the DataFieldParentID property.

Any ideas? And also - As this is a dynamically created control, I'm having trouble picking up the selected nodes. I'm adding the control at OnInit and Viewstate is enabled. Is there anything I need to do?

Thanks.


2 Answers, 1 is accepted

Sort by
0
Veronica
Telerik team
answered on 19 Feb 2010, 11:17 AM
Hi John,

Thanks for you question.

As I take a look on your code it seems that DataFieldID property is missing.

Please take a look at this live demo about programmatic data binding.
If you still have questions please attach the full code.

Let me know if this was helpful.

Sincerely yours,
Veronica Milcheva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
John
Top achievements
Rank 1
answered on 19 Feb 2010, 11:21 AM
Thanks - I'll try this.

And I figured out the issue with the selections not being picked up - I actually wanted to pickup checked items, not selected items - I only just realised that the 2 are different.

Thanks
Tags
TreeView
Asked by
John
Top achievements
Rank 1
Answers by
Veronica
Telerik team
John
Top achievements
Rank 1
Share this question
or