Need help with asp c# treeview mouseover get node value/text

LeClair, Michael L. (Rumford) 21 Reputation points
2020-12-13T16:18:23.477+00:00

I want to use a mouseover event to get the current node value/text from the mouseover on a treeview. This is using ASP C# treeview. Can anyone help!? Have not seen online any clear examples of this.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,437 questions
{count} votes

Accepted answer
  1. Yijing Sun-MSFT 7,071 Reputation points
    2020-12-15T07:10:18.22+00:00

    Hi @LeClair, Michael L. (Rumford) ,

    Accroding to your description,as far as I think,you need to get and split the node's path to find the node's value.Just like this:

    TreeView1.Attributes.Add("onmouseover", "return OnTreeMmouseover(event)");  
     
    function OnTreeMmouseover(evt) {  
        var src = window.event != window.undefined ? window.event.srcElement : evt.target;  
        var nodeClick = src.tagName.toLowerCase() == "a";  
        if (nodeClick) {  
            var nodeText = src.innerText || src.innerHTML;  
            var nodeValue = GetNodeValue(src);   
            a lert("Text: " + nodeText + "," + "Value: " + nodeValue);  
        }  
        return false;  
    }  
    function GetNodeValue(node) {  
        var nodeValue = "";  
        var nodePath = node.href.substring(node.href.indexOf(",") + 2, node.href.length - 2);  
        var nodeValues = nodePath.split("\\");  
        if (nodeValues.length > 1)  
            nodeValue = nodeValues[nodeValues.length - 1];  
        else  
            nodeValue = nodeValues[0].substr(1);  
        return nodeValue;  
    }  
    

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Yijing Sun


0 additional answers

Sort by: Most helpful