ASP.NET: get node selected in ASP.NET TreeView by JavaScript client side

I need to know the selected node depth from the client side ASP.NET tree tree.

Does anyone even know this?

Thanks!

+1


a source to share


1 answer


Not that I enjoy doing this, and if time permits, I will try to 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 this helps. If you find an alternative, please post back.

+1


a source







All Articles