user274139
user274139

Reputation: 91

asp.net treeview by avoiding collapse and expandall

I am using ASP.NET with C# 2.0 and Visual Studio 2005. I am using a Master page and content pages. I have a treeview menu in the master page and when a user selects any menu item I redirect to that content page.

My problem is that after a user navigates to the content page all the treenodes refresh and the structure is collapsed. I want the selected treenode to stay expanded.

Can anybody help me out?

Upvotes: 0

Views: 771

Answers (1)

Kangkan
Kangkan

Reputation: 15571

Are you using the treeview inside any UpdatePanel? Actually UpdatePanel does not support TreeView. I however managed the same using a lot of additional codes. You can see most of them on http://www.geekays.net/post/Using-TreeView-inside-AJAX-UpdatePanel.aspx and another post on the same site: http://www.geekays.net/post/TreeView-control-postbacks-on-check-and-uncheck-of-the-nodes-Checkbox.aspx

I added javascripts like the following also to scroll to a tree node that was selected, but the success was poor:

function scrollSelectedTviewNodeToDisplay(){
    try{    
        var inpSelectedNode = document.getElementById("ctl00_contRMSMaster_TViewDeviceHeirarchy_SelectedNode");
        var divTree = document.getElementById("ctl00_contRMSMaster_TViewDeviceHeirarchy");
        if (inpSelectedNode.value != "")
        {
            var objScroll = document.getElementById(inpSelectedNode.value);
            //my treeview is contained in a scrollable div element
            var posY =findPosY(objScroll);
            //alert(posY);
            if (divTree){
                divTree.scrollTop = posY;
                //alert(divTree.nodeType);
            }
            //this works as well bu, but there is not as much control over the y position
            //document.all(inpSelectedNode.value).scrollIntoView(true);
        }
    }
    catch(oException) 
        {
            //alert(document.getElementById("ctl00_contRMSMaster_divTree"));
        }
}

function findPosX(obj){
    var curleft = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj){
    var curtop = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}

Upvotes: 1

Related Questions