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

[Solved] MVC Treeview - How to Set Selected?

2 Answers 223 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
rob cooney
Top achievements
Rank 1
rob cooney asked on 20 Aug 2010, 04:48 PM
HI,

I'm using the MVC Telerik Treeview control, and using the OnDataBinding to load the contents from the server:

<%= Html.Telerik().TreeView()
            .Name("AjaxTreeView")
            .ClientEvents(events => events
            .OnDataBinding("onDataBinding")
            )                
            %>

function onDataBinding(e) {
           
            var path = mycontrollerpath;
            $.get(path, function(data) {
                var treeview = $('#AjaxTreeView').data('tTreeView');
                treeview.bindTo(data);              
            });                        
        } 

How do I Select the initially selected item/index?
I've tried using OnDataBound client event - but it doesnt seem to fire.

2 Answers, 1 is accepted

Sort by
0
Christopher Ronak
Top achievements
Rank 1
answered on 28 Sep 2010, 02:52 PM
Hi Rob,
Did you ever figure out how to do this?
What I'm hoping to do is use the API to visually select a node. 

Thanks for anyone's help!

Chris
0
al
Top achievements
Rank 1
answered on 01 Feb 2011, 12:13 AM
Hi mate , here is what i worked out.

 function onDataBinding(e) {
            var treeview = $('#TreeView').data('tTreeView');
            var jsonObject;
            if (e.item == treeview.element) {
                jsonObject =  <%= Model.type%>;
                treeview.bindTo(jsonObject);
                 var item = $("> ul > li > div > span.t-in", treeview.element)['0'];
                $(item).addClass("t-state-selected");
            } 
        }
Tags
TreeView
Asked by
rob cooney
Top achievements
Rank 1
Answers by
Christopher Ronak
Top achievements
Rank 1
al
Top achievements
Rank 1
Share this question
or