1

I need to know the selected node's depth from a ASP.NET Treeview on client side.

Is there anyway to know this?

Thank you!

1 Answer 1

1

Not that I like doing it this way and if time permits I'll try and find another method;

        var id = TreeView2_Data.selectedNodeID.value;  //Get the Selectednode id of tv with asp.net id of TreeView2
    if (id.length > 0) {
        var selectedNode = document.getElementById(id);  //Get the Selectnode object  -> selectedNode.innerText will give you the text of the node
        if ((typeof (selectedNode) != "undefined") && (selectedNode != null)) {
            //Determine the depth of the select node
            var nodeDepth = selectedNode.host.split('\\\\').length  // the separator is the default single \. Tv adds the extra on and of course we have to add 2 for the string literals.
            //node depth wil always be one more than the real node depth, so root is one.
            if (nodeDepth >= 4) {   
                //Do stuff or return value
            }
        }
    }

Hope it helps. Post back if you find an alternative.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.