0
votes

im using treeview in asp.net

treeview like

*parent
   @child1
     .child2
*parent
   .child

if i click child2 after postback the alignment which is in above should not change

but parent1 should be collapsed

if i click child then parent node should be collapsed

im using thi following code

  protected void Page_Load(object sender, EventArgs e)
    {
         if (Session["tvExpandNode1"] != null)
        {
            TreeView1.FindNode(Session["tvExpandNode1"].ToString()).Expand();

        }
    }

  protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
           if (TreeView1.SelectedNode.Expanded == true)
                {
                    Session["tvExpandNode1"] = TreeView1.SelectedNode.Parent.Parent.Value;
                    if (strOpenpage == "Report.aspx")
                    {
                        OpenNewWindow(strOpenpage);
                    }
                    else
                    {
                        Response.Redirect(strOpenpage, false);
                    }
                }   
    } 

its just not working properly...pls provide ur valuable infromation........

1

1 Answers

0
votes

I don't know if your problem is this but if you want to expand the leaf nodes, you need to expand all parent nodes. Here is a recursive function.

void expandParentNode(TreeNode node)
{
    if (node == null)
        return;

    node.Expand();
    expandParentNode(node.Parent);
}