Changing default node behaviour

3 posts, 1 answers
  1. Michael Dunbar
    Michael Dunbar avatar
    129 posts
    Member since:
    Sep 2007

    Posted 06 Jan 2010 Link to this post

    Hello,

    I want my treeview nodes to behave slightly differently to the default in that when a node that has child nodes is clicked the postback is disabled and the node is simply expanded. I will be wanting to raise a postback and fire the node click event when a node that does not have child nodes is clicked.

    I tried a server side approach on the node data bound event by trying to count the e.Node.Nodes to see if it had children that way but it was always returned as 0. Is there a server or client side approach I can use to achieve the node behavior I require?

    Thanks,

    Michael
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Jan 2010 Link to this post

    Hello Michael,

    Attach 'OnClientNodeClicking' event and check for if there is any child nodes, if yes cancel the event using args.set_cancel(true) method and expand the node in the handler. Here is the code that I tried.

    aspx:
     
    <telerik:RadTreeView ID="RadTreeView2" runat="server" OnClientNodeClicking="OnClientNodeClicking" 
        OnNodeClick="RadTreeView2_NodeClick"
        <Nodes> 
         . . . 
        </Nodes> 
    </telerik:RadTreeView> 

    javacript:
     
    <script type="text/javascript"
        function OnClientNodeClicking(sender, args) { 
            if (args.get_node().get_nodes().get_count() > 0) { 
                args.get_node().set_expanded(true); 
                args.set_cancel(true); 
            } 
        } 
    </script> 

    cs:
     
        protected void RadTreeView2_NodeClick(object sender, RadTreeNodeEventArgs e) 
        { 
     
        } 

    -Shinu.
  3. Michael Dunbar
    Michael Dunbar avatar
    129 posts
    Member since:
    Sep 2007

    Posted 06 Jan 2010 Link to this post

    Thanks Shinu. I'll give that a go now.
Back to Top