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

data binding to a custom attribute

2 Answers 109 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Charles Forsyth
Top achievements
Rank 2
Charles Forsyth asked on 12 Sep 2008, 05:33 PM
Hello again gurus,

Is it possible to bind (using a datasource) to a custom attribute in the radTreeView?

If so how would I do that?

If not, here's what I'm trying to accomplish, perhaps you can offer advise...

My hierarchical list of data provided by the datasource contains not only the ID of the record, the ID of the parent record and the name of the record, it also provides the name of the parent.

What I'm trying to do is create a drop-down list out of the radTreeView control. I have a textbox control set up with the Ajax Control Toolkit's "DropDownExtender" control. 

When the user selects a node in the RadTreeView, I wish to display the path to that node in the textbox using client-side JavaScript.
 
My problem is, I don't know how to access the ParentName of the datasource associated with the node selected. I figured it would be easiest to create a custom attribute out of it and access it that way (and recurse a loop up to the null parent, to provide a path for the user interface)

Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 15 Sep 2008, 03:45 PM
Hello Charles Forsyth,

You can handle the NodeDataBound event, which fires for each Node that is being bound, of the RadTreeView and set the custom attribute there.

A similar example is demonstrated here (with the difference that the ToolTip of a Node is set instead).

Greetings,
Simon
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Charles Forsyth
Top achievements
Rank 2
answered on 15 Sep 2008, 04:00 PM
Thanks for the reply.

I actually decided to go about it a different way, I couldn't wait.

I created a User Control that has three parts: The RadTreeView, a TextBox and a HiddenField.

I wrote a JavaScript function that is hooked up to the client node click event.

First it associates the clicked ID to the hidden field. Then it populates the textbox text and title properties with the full path based on the tree itself by iterating through each parent node until the parent node is found to be the treeview itself.

It's a simple solution but it works.

    function ServiceLineNodeClicked(sender, eventArgs) {  
        var hiddenField = $get("<%= HiddenField_SLP.ClientID %>");  
        var node = eventArgs.get_node();  
        if (hiddenField) { hiddenField.value = node.get_value(); }  
        var textbox = $get("<%= TextBox_SLP.ClientID %>");  
        if (textbox) {  
            var path = node.get_text();  
            var parentNode = node.get_parent();  
            while (parentNode != node.get_treeView()) {  
                path = parentNode.get_text() + ' > ' + path;  
                parentNode = parentNode.get_parent();  
            }  
            textbox.value = path;  
            textbox.title = path;  
 
        }  
    } 

Tags
TreeView
Asked by
Charles Forsyth
Top achievements
Rank 2
Answers by
Simon
Telerik team
Charles Forsyth
Top achievements
Rank 2
Share this question
or