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

Is NodeDataBound called recursively?

2 Answers 71 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Michal
Top achievements
Rank 1
Michal asked on 12 May 2009, 07:59 AM
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 Answers, 1 is accepted

Sort by
0
Michal
Top achievements
Rank 1
answered on 18 May 2009, 11:21 AM
No one can help nor can anyone give feedback?
Best regards
Michal
0
Atanas Korchev
Telerik team
answered on 18 May 2009, 12:33 PM
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.
Tags
TreeView
Asked by
Michal
Top achievements
Rank 1
Answers by
Michal
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or