0
votes

Im using Treeview in asp.net

Treeview like

PARENT1

#Child
   .Subchild1
   .Subchild2

PARENT2 #child1 #child2

first when my page load at first time all nodes should be collapsed like

PARENT1 PARENT2

If i expand PARENT1 and click subchild2 as by my senario my page is rediected and parent1 should be expanded and parent2 should be collapsed....

if i click parent2 vise versa...

so i have to maintain tree position level in every postback any solution for this?

im using the following code

but i got error 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); } } }

1

1 Answers

0
votes

Yes, you can write code to do this with the standard ASP.NET treeview to do this. I know some controls support binding to a sitemap and this control should be able to be bound to a sitemapdatasource, if your tree is related to the current page hierarchy. I don't know that that gives you automatic expand/collapse based upon the selected node. You could toy with that if your tree is based on the sitemap. Otherwise, programmatically this can be handled, but haven't heard of anything to give you this out of the box...