Hi Guys

I am created a tree view in a usercontrol..and used it in master page.

But when i access the pages inside the parent node.the treeview is coming back to normal form.

but i want the parent node to be expanded until i am using pages from that section.

can any body please help me how to do that..

My code in user control is ..


thanks

public partial class leftmenu : System.Web.UI.UserControl
{
    private string sectionName;
    private TreeNode currentNode;
    private TreeNode parentNode;
    public MasterPage Masterpage;

    protected void Page_Load(object sender, EventArgs e)
        {

        }
        public void SetSectionName(string name)
        {
            sectionName = name;
        }
        private void CheckSelectedNodes(TreeNodeCollection nodes, string selected)
        {
            foreach (TreeNode node in nodes)
            {
                //Response.Write(node.Text + " = " + selected + " and " + node.NavigateUrl + "<br />");

                if (node.Text == selected)
                {
                    currentNode = node;
                    if (node.Parent != null)
                    {
                        parentNode = node.Parent;
                    }
                    return;


                }
                node.Expand();
                CheckSelectedNodes(node.ChildNodes, selected);
                node.Expand();
            }
        }
       //// public EazyShop.Admin.Master MasterPage
       // //{
       //     get { return (EazyShop.Admin.Master)Page.Master; }
       // }
        protected void LeftSiteMap_DataBound(object sender, EventArgs e)
        {

            CheckSelectedNodes(LeftSiteMap.Nodes, sectionName);
            LeftSiteMap.Nodes[0].Expand();
            if (currentNode != null)
            {
                currentNode.Selected = true;
                currentNode.ExpandAll();
            }
            if (parentNode != null) parentNode.Expand();
        }

         private void CheckSelectedNodes2(TreeNodeCollection nodes, string selected)
        {
            foreach (TreeNode node in nodes)
            {
                if (node.Text == selected)
                {
                    currentNode = node;
                    currentNode.Parent.Expand();
                }

            }
         }
        }

1. Store the information about Selected/Expanded Node in Session.
2. On Page load event, extend the appropriat node after binding

Also visit this link.

A solution is given in the above link. But the tree node collection are stored in the Session. You can check if it addresses you problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.