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

Changing default node behaviour

2 Answers 53 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Michael Dunbar
Top achievements
Rank 2
Michael Dunbar asked on 06 Jan 2010, 10:56 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 06 Jan 2010, 01:35 PM
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.
0
Michael Dunbar
Top achievements
Rank 2
answered on 06 Jan 2010, 01:37 PM
Thanks Shinu. I'll give that a go now.
Tags
TreeView
Asked by
Michael Dunbar
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Michael Dunbar
Top achievements
Rank 2
Share this question
or