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

RadTreeNodeData missing properties

3 Answers 154 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 2
Thomas asked on 28 Apr 2009, 07:57 AM
How could I use in a WebService to load the childs of the parent with RadTreeNodeData like ToolTip, Expanded and AllowEdit?

All other properties (eg: Text, Value) are in the RadTreeNodeData object like RadTreeNode.

eg:

Telerik.Web.UI.RadTreeNode node = new Telerik.Web.UI.RadTreeNode();
node.Text = "new node";
node.Value = "25";
node.ToolTip = row["Tooltip"].ToString();


RadTreeNodeData nodeData = new RadTreeNodeData();
nodeData.Text = "new node";
nodeData.Value = "25";
??nodeData.ToolTip??

regards
Thomas

3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 01 May 2009, 08:09 AM
Hello Thomas,

There are two approaches you can use in this way.

First approach - using a custom class:

1. Create a class that inherits the RadTreeNodeData class and add the ToolTop property to it:

public class CustomRadTreeNodeData : RadTreeNodeData 
    public string ToolTip; 

2. Define the WebMethod as follows:

[WebMethod] 
public CustomRadTreeNodeData[] GetNodesWithToolTips() 
    List<CustomRadTreeNodeData> nodes = new List<CustomRadTreeNodeData>(); 
 
    for (int i = 1; i < 11; i++) 
    { 
        CustomRadTreeNodeData node = new CustomRadTreeNodeData(); 
        node.Text = "node " + i.ToString(); 
        node.ToolTip = "Tooltip for " + node.Text; 
        nodes.Add(node); 
    } 
 
    return nodes.ToArray(); 

3. Set the tooltip of the node in the OnClientNodeDataBound event:

<script type="text/javascript"
function OnClientNodeDataBoundHandler(sender, e) 
    var node = e.get_node(); 
    node.set_toolTip(e.get_dataItem().ToolTip);     
</script>     


The second option is similar, but instead of creating a new class you use the Attributes dictionary to store the ToolTip:

1. Add the ToolTip custom attribute:

[WebMethod] 
public RadTreeNodeData[] GetNodesWithToolTips() 
    List<RadTreeNodeData> nodes = new List<RadTreeNodeData>(); 
 
    for (int i = 1; i < 11; i++) 
    { 
        RadTreeNodeData node = new RadTreeNodeData(); 
        node.Text = "node " + i.ToString(); 
        node.Attributes["ToolTip"] = "new tooltip for " + node.Text; 
        nodes.Add(node); 
    } 
 
    return nodes.ToArray(); 

2. Set the tooltip of the node in the OnClientNodeDataBound event:

<script type="text/javascript"
function OnClientNodeDataBoundHandler(sender, e) 
    var node = e.get_node(); 
    node.set_toolTip(node.get_attributes().getAttribute("ToolTip")); 
</script>     

I hope this helps.

Best wishes,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Claudiu
Top achievements
Rank 1
answered on 23 Mar 2012, 06:49 PM
hi Veselin,

I'm using the technique described below (custom RadTreeNodeData class) for passing more information for each node. However when I do access the custom properties on the client-site, they do not exist (I'm getting a value of "undefined").

Here is how I've done it:
public class CustomRadTreeNodeData  : RadTreeNodeData
{
public int CustomProperty { get; set; }
}

On the client-side I have the following handler bound to OnClientNodeDataBound event:
function clientNodeDataBound(sender, eventArgs) {
            var node = eventArgs.get_node();
            var dataItem = eventArgs.get_dataItem();
 
            var nodeType = dataItem.CustomProperty; // this is 'undefined'
        }


Am I doing something wrong here?

Thanks,
Claudiu
0
Plamen
Telerik team
answered on 27 Mar 2012, 11:42 AM
Hello Claudiu,

 
I will recommend you to check if the CustomRadTreeNodeData is set everywhere properly in the web method as well.

I am attaching a sample working project.

Hope this will help you.

Regards,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
TreeView
Asked by
Thomas
Top achievements
Rank 2
Answers by
Veselin Vasilev
Telerik team
Claudiu
Top achievements
Rank 1
Plamen
Telerik team
Share this question
or