views:

1789

answers:

3

Hi all.

I've a TreeView that displays hierarchical data, while I select a TreeNode, I generate a series of links that map the path from selected node till root node

Say: Root Node --> ChildNode --> SelectedNode

What I need is, while clicking any of these links, select required node in TreeView?

I know that selecting a TreeNode is done through ClientSide using this code:

javascript:__doPostBack(TreeView.ClientID,TreeNodeValuePath)

and

TreeView_SelectNode(TreeView.ClientID_Data, this,TreeNode.ClientID)

Ex:

    <a style="border-style: none; font-size: 1em;" id="tvMenut1" title="Created On: 1/28/2009 9:50:06 AM" onclick="TreeView_SelectNode(tvMenu_Data, this,'tvMenut1');" href="javascript:__doPostBack('tvMenu','s1\\720,63')" class="tvMenu_0 treenodeParent tvMenu_3">
Etravel2000

My problem is to get TreeNode.ClientID?

Any suggestion? FYI: this page is an AJAX-Enabled page.

A: 

TreeNode.ClientID as int the ASP.Net control ClientID?

If so, drop this wherever you're trying to pass it: <%= TreeNode.ClientID %>

NTulip
A: 

There is no a TreeNode.ClinetID property for TreeNode object.

Ahmed
A: 

You can get ClientID of a TreeNode using the following method. You can change which parameter you will use to get a node based on it.

    function GetTreeNodeID(nodeTooltip)
    {
        var tree = document.getElementById(TreeView.ClientID); // Change TreeView ClientID.
        var treeLink =  tree.getElementsByTagName('A');    

        for(var element in treeLink)
            if((nodeTooltip == treeLink[element].title) && (treeLink[element].title != ""))                      
                return treeLink[element].id;
    }

Then use this code for each TreeNode in TreeView.

spanPath.InnerHtml += "<a href=\"javascript:__doPostBack('tvMenu','" + targetNode.ValuePath + "')\" onclick=\"TreeView_SelectNode(tvMenu_Data, this, GetTreeNodeID('" + targetNode.ToolTip + "'));\">" + targetNode.Text + "</a>&nbsp;&nbsp;-->&nbsp;&nbsp;";

While you select a node from spanPath, it will be selected in TreeView.

Ahmed