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

RadTreeView and databinding on a sub object

2 Answers 28 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 1
Anthony asked on 11 Jul 2012, 11:10 AM
Hi,

I'm being given data from our DAL which returns properties, such as ParentContent.ID, however when I pass this to the TreeView it fails on databind, please see my below code:

this.rtv_LeftMenu.DataSource = contentList;
this.rtv_LeftMenu.DataTextField = "Title";
this.rtv_LeftMenu.DataFieldID = "ID";
this.rtv_LeftMenu.DataValueField = "ID";
this.rtv_LeftMenu.DataFieldParentID = "ParentContent.ID";
this.rtv_LeftMenu.Style.Add("margin", "5");
this.rtv_LeftMenu.Style.Add("padding", "5");
this.rtv_LeftMenu.DataBind();

At run time I get a NotSupportedException saying it can't find the property ParentContent.ID. I have checked to make sure the property exists and is accessible. Please let me know if there is a way to get the TreeView control to accept properties like this?

I had this working with our previous DAL, so am confident that everything else is working correctly.

Many thanks.

2 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 11 Jul 2012, 12:10 PM
Hello Anthony,

I would have to assume that ParentContent will sometimes be null, if the item has no parent. So trying to access the ID property would through an exception when the ParentContent object is null.

I would suggest adding your ParentID as a property to the value. So something like ParentContentID, which returns either the value of the id or null for those that have no parent.

I hope that helps.
0
Anthony
Top achievements
Rank 1
answered on 11 Jul 2012, 01:07 PM
Hi Kevin,

You are right about ParentContent being null and I have already implemented ParentContentID as a work around, thanks for you reply and quick response.

Cheers.
Tags
TreeView
Asked by
Anthony
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Anthony
Top achievements
Rank 1
Share this question
or