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

RadTreeView, Templates and Server Side Callback

10 Answers 371 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Joe Aubin
Top achievements
Rank 1
Joe Aubin asked on 02 Jun 2008, 09:18 PM
I am in the process of converting my RadTreeView to use the ASP AJAX RadTreeView and I am having some trouble. I have a NodeTemplate that uses DataBinder.Eval() calls to build the template. On the server, I get a hierarchical datasource and manually add the nodes (not using a databind). This would add the nodes but none of the DataBinder tags were being resolved. I read in your documentation that I needed to call DataBind() on the treeview control. I added that call and the tags are being resolved and the templates are working.

Now the problem is when I try to expand a node that wasn't initially expanded. I am using the ServerSideCallBack mode on the node. The NodeExpanded event will fire and I will manually add the child nodes to the selected/expanded nodes but once again, the template isn't working and the DataBinder.Eval calls are not being made. I have tried calling DataBind on the nodes being added, the node that was expanded and the RadTreeView control itself but to no avail.

Any ideas and help would be appreciated.

10 Answers, 1 is accepted

Sort by
0
Joe Aubin
Top achievements
Rank 1
answered on 03 Jun 2008, 02:20 PM
Anyone??
0
Joe Aubin
Top achievements
Rank 1
answered on 04 Jun 2008, 01:14 PM
Can someone from Telerik offer ANY help on this question?
0
Veselin Vasilev
Telerik team
answered on 04 Jun 2008, 03:00 PM
Hi Joe Aubin,

You need to call DataBind() of the newly added node in the NodeExpand event handler.

I have attached a small project that demonstrates the approach. Download it and give it a try.

I hope this helps.

Kind regards,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Joe Aubin
Top achievements
Rank 1
answered on 04 Jun 2008, 05:51 PM
Thank you for the reply. However, as I mentioned in my original post, I have tried calling DataBind() on the newly added nodes but it does not seem to work for me. I tried your sample code and that does indeed work but my code doesn't bind and the template is not evaluated.

My RadTreeView is nested pretty deep within some other controls so could this be a problem? It is nested within a RadPanel which is nested within a RadSplitter, etc. I don't know why this would be a concern but I am grasping at straws and this problem is causing me a lot of heartache. Here is my treeview declaration in my ASCX file:


                <radTree:RadTreeView ID="trvControl" 
                    runat="server" 
                    MultipleSelect="false"   
                    RetainScrollPosition="true" 
                    LoadingMessage = "Loading..." 
                    LoadingStatusPosition="AfterNodeText" 
                    SingleExpandPath="false" 
                    AllowNodeEditing="false" 
                    OnNodeExpand="trvControl_NodeExpand">  
                    <NodeTemplate> 
                        <span> 
                            <span id="<%# trvControl.ClientID %>_dvNm_<%# DataBinder.Eval(Container, "Value") %>" class="MouseOutTreeNodeLabel">  
                                <%# DataBinder.Eval(Container, "Text") %> 
                                <span id="<%# trvControl.ClientID %>_dvBtnAcqGp_<%# DataBinder.Eval(Container, "Value") %>_MenuPB" class="MouseOutTreeNodeImage" > 
                                    <img style="padding-left:4px;" id="<%# trvControl.ClientID %>_BtnAcqGp_<%# DataBinder.Eval(Container, "Value") %>_ImageButton" src="Images/menubutton.gif" alt="Menu" /> 
                                </span> 
                            </span> 
                        </span> 
                        <div id="<%# trvControl.ClientID %>_myDiv_<%# DataBinder.Eval(Container, "Value") %>" style="display:none">                              
                        </div> 
                    </NodeTemplate> 
                </radTree:RadTreeView> 

and my C#:

        protected override void trvControl_NodeExpand(object o, RadTreeNodeEventArgs e)  
        {  
            IList items = GetNodeItems(int.Parse(e.Node.Value));  
            if (items.Count > 0)  
            {  
                SmartObj rootNode = items[0] as SmartObj; //get the parent   
                for (int i = 0; i < rootNode.Children.Count; i++)  
                {  
                    SmartObj newNode = rootNode.Children[i] as SmartObj;  
                    RadTreeNode newTreeNode = new RadTreeNode();  
                    PopulateNodeData(newNode, newTreeNode);  
                    e.Node.Nodes.Add(newTreeNode);  
                    newTreeNode.DataBind();  
                }  
            }  
        } 


Despite calling DataBind() on the newly added nodes, I end up with empty nodes under the expanded node. If I break into my JSON objects and look at the HTML, nothing within the <%# % databinding tags is present. 
0
Joe Aubin
Top achievements
Rank 1
answered on 05 Jun 2008, 02:54 PM
So I think that I have determined what the problem is, but I am unsure as to what is causing it.

The difference in the sample code and in my code is that when the NodeClicked callback occurs, e.Node.TreeView is NULL in my code but it is valid in the sample code. This is obviously a problem because the new node doesn't have a treeView and thus doesn't have the NodeTemplate. For kicks and giggles, I did the following to test my theory...

((RadTreeView)o).Nodes.Add(e.Node)

thus adding the clicked node to the "sender" object. Now the new node has a TreeView object and the template is correctly bound.

So any idea as to why I am losing the e.Node.TreeView object on callback? Setting EnableViewState to true has no effect.
0
Veselin Vasilev
Telerik team
answered on 09 Jun 2008, 07:44 AM
Hello Joe Aubin,

It is really strange indeed. We could not reproduce the problem, so could you isolate it in a simple running project and send it to us? We will test it locally and find the solution quicker.

Thanks

Regards,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Ofer Tiber
Top achievements
Rank 1
answered on 07 Oct 2010, 05:10 PM

Hi.

I downloaded a code from your post and managed how the procedure (LoadOnDemand) works, but new problem appeared.

I place RadTreeView control inside UpdatePanel (MS). The nodes (ondemand) added well, but when I attach an OnNodeClick event to the control, by clicking on any node, the new nodes that added on demand, text disappeared.

the code:

<asp:UpdatePanel runat="server">
  <ContentTemplate>
     <telerik:RadTreeView ID="RadTreeView1"             
            runat="server" OnNodeClick="NodeClicked"
            OnNodeExpand="RadTreeView1_NodeExpand">
            <NodeTemplate>
                <%# DataBinder.Eval(Container, "Text"%>
            </NodeTemplate>
        </telerik:RadTreeView>
   </ContentTemplate>
</asp:UpdatePanel>

Thanks in advance
P.S.Event Handler method "NodeClicked" do nothing
0
Nikolay Tsenkov
Telerik team
answered on 12 Oct 2010, 11:29 AM
Hi Ofer Tiber,

Well you can use the property - PersistLoadOnDemmandNodes.

Please, try that out and let me know about the results.


Regards,
Nikolay Tsenkov
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
Nathan
Top achievements
Rank 1
answered on 04 Nov 2010, 01:19 PM
Hi,

I need help to solve my issue, here is my case, I have radTreeview and it has node1 with checkbox (for an example) and the node has 4 child nodes. when I clicked on the node1 all the child nodes gets selected.

I need to  uncheck the node1 when no child is selected. Is there any property to find the parent node of the child node?
0
Nikolay Tsenkov
Telerik team
answered on 09 Nov 2010, 02:21 PM
Hello Senthil,

On the client side the property is node.get_parent() . On the server it's node.Parent.

Hope this is helpful for you!


Regards,
Nikolay Tsenkov
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
Tags
TreeView
Asked by
Joe Aubin
Top achievements
Rank 1
Answers by
Joe Aubin
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Ofer Tiber
Top achievements
Rank 1
Nikolay Tsenkov
Telerik team
Nathan
Top achievements
Rank 1
Share this question
or