How to prevent tree clotting?

I am using ASP.NET with C # 2.0 and Visual Studio 2005. I am using the home page and content page. I have a treeview menu on the main page, and when the user selects any menu item, I am redirected to this content page.

My problem is that after the user goes to the content page, all treenodes updates and structure will be collapsed. I want the selected treenode to stay extended.

Can anybody help me?

+3
source share
4 answers

When you update the tree structure that treeView1.ExpandAll ();

BeforeCollapse "" "", treenodes.

private void treeView1_BeforeCollapse(object sender, TreeViewCancelEventArgs e)
{
    e.Cancel = true;
}

, .

-jeremy

+16

, ASP.NET, SiteMapDataSource TreeView. , Datasource TreeView.

, TreeView ( NavigateUrl) , . , , , ! , TreeNodes, NavigateUrl. .

, , , :

a. SelectedNodeChanged TreeView. SelectedNode.ValuePath ViewState/Session. Value SelectedNode URL, .

- :

protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) 
{ 
  TreeNode selNode = TreeView1.SelectedNode; 
  string pathToNode = selNode.ValuePath; 
  Session.Add("SelPath", pathToNode); 

  switch (selNode.Value) 
  { 
  //Redirect to URL accordingly. 
  } 
} 

b. (, ), ValuePath node Expand .

- :

protected void Page_Load(object sender, EventArgs e) 
{ 
  if (Page.IsPostBack)
  { 
    string pathToNode = (string)Session("SelPath"); 
    Session.Remove("SelPath"); 
    TreeNode selNode = TreeView1.FindNode(pathToNode); 
    if (selNode != null) 
    { 
      selNode.Expand(); 
    } 
  } 
} 

, , .

+2

OnTreeNodeDataBound treeView.SelectedNode

, , / TreeView DataSource. IsPostBack, .

TreeView PostBack.

0

Even though you are using the main page, as soon as the user goes to the content page, it is displayed as a new / different page. Because of the main page, the same tree is loaded, but not the same instance. You will need to store and load the nodes.

0
source

Source: https://habr.com/ru/post/1704843/


All Articles