Is NodeDataBound called recursively?

3 posts, 0 answers
  1. Michal
    Michal avatar
    4 posts
    Member since:
    Mar 2009

    Posted 12 May 2009 Link to this post

    Hi,
    I am completely new to telerik... We are about to buy but I am having some troubles to get started ..
    I try to bind the treeview to the following structure:

    - Assessment
      - Folder
        - Folder
        ....
    - Assessment

    (assessment is an own domain object and folder too)

    I am getting all assessment as a list<Assessment> and those can contain 0-n folders. I tried to bind the treeview to the assessments and call the assessments Folders property within NodeDataBound.

    Thats the page_load:

    protected void Page_Load(object sender, EventArgs e) { 
            if (!IsPostBack) { 
                RadTreeView1.DataSource = new NHibernateDaoFactory().GetTagGroupDao().GetAll(); 
                RadTreeView1.DataBind(); 
                RadTreeNode untaggedNode = new RadTreeNode(GetLocalResourceObject("res_untagged").ToString(), ""); 
                untaggedNode.AllowDrag = true
                untaggedNode.Checkable = true
                RadTreeView1.Nodes.Add(untaggedNode); 
     
                uxTreeAssessments.DataSource = new NHibernateDaoFactory().GetAssessmentDao().GetAll(); 
                uxTreeAssessments.DataFieldID = "ID"
                uxTreeAssessments.DataValueField = "ID"
                uxTreeAssessments.DataTextField = "LocalizedName"
                uxTreeAssessments.DataBind(); 
            } 
        } 

    And then the nodedatabound:

    protected void uxTreeAssessments_NodeDataBound(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e) { 
            if (e.Node.Level == 0) { 
                Assessment a = e.Node.DataItem as Assessment; 
                foreach (Folder f in a.Folders) { 
                    RadTreeNode n = new RadTreeNode( 
                        string.Format("{0} ({1})", f.LocalizedName, f.Questions.Count), 
                        f.ID.ToString()); 
                    n.DataItem = f; 
                    e.Node.Nodes.Add(n); 
                } 
            } else if (e.Node.Level > 0) { 
                Folder parent = e.Node.DataItem as Folder; 
                foreach (Folder f in parent.Folders) { 
                    RadTreeNode n = new RadTreeNode( 
                        string.Format("{0} ({1})", f.LocalizedName, f.Questions.Count), 
                        f.ID.ToString()); 
                    n.DataItem = f; 
                    e.Node.Nodes.Add(n); 
                } 
            } 
        } 

    The problem is that the ELSE IF part is never called ... and thus the sub folders of the folders are not rendered.

    Any assistance would be appreciated as I am stuck here.. Not even sure if the approach is correct.
    Thanks!!
  2. Michal
    Michal avatar
    4 posts
    Member since:
    Mar 2009

    Posted 18 May 2009 Link to this post

    No one can help nor can anyone give feedback?
    Best regards
    Michal
  3. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 18 May 2009 Link to this post

    Hi Michal,

    I think in your case RadTreeView creates only root nodes during databinding. You need to set the DataFieldID/DataFieldParentID properties in order to create node hierarchy. You can check this help topic and this online example for more info.

    Sincerely yours,
    Albert
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top