RadTreeView, Templates and Server Side Callback

11 posts, 0 answers
  1. Joe Aubin
    Joe Aubin avatar
    9 posts
    Member since:
    Sep 2006

    Posted 02 Jun 2008 Link to this post

    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.

  2. Joe Aubin
    Joe Aubin avatar
    9 posts
    Member since:
    Sep 2006

    Posted 03 Jun 2008 Link to this post

    Anyone??
  3. Joe Aubin
    Joe Aubin avatar
    9 posts
    Member since:
    Sep 2006

    Posted 04 Jun 2008 Link to this post

    Can someone from Telerik offer ANY help on this question?
  4. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 04 Jun 2008 Link to this post

    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
  5. Joe Aubin
    Joe Aubin avatar
    9 posts
    Member since:
    Sep 2006

    Posted 04 Jun 2008 Link to this post

    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. 
  6. Joe Aubin
    Joe Aubin avatar
    9 posts
    Member since:
    Sep 2006

    Posted 05 Jun 2008 Link to this post

    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.
  7. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 09 Jun 2008 Link to this post

    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
  8. Ofer Tiber
    Ofer Tiber avatar
    2 posts
    Member since:
    Apr 2006

    Posted 07 Oct 2010 Link to this post

    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
  9. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 12 Oct 2010 Link to this post

    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
  10. Nathan
    Nathan avatar
    13 posts
    Member since:
    Aug 2010

    Posted 04 Nov 2010 Link to this post

    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?
  11. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 09 Nov 2010 Link to this post

    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
Back to Top