RadTreeView and databinding on a sub object

3 posts, 0 answers
  1. Anthony
    Anthony avatar
    2 posts
    Member since:
    Dec 2010

    Posted 11 Jul 2012 Link to this post


    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");

    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. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 11 Jul 2012 Link to this post

    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.
  3. Anthony
    Anthony avatar
    2 posts
    Member since:
    Dec 2010

    Posted 11 Jul 2012 Link to this post

    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.

Back to Top