我在web下建了一棵树,有好几个根结点,我想在打开一个根结点的时候,其它打开的根结点多收起来,应该怎么做呢?还有,我把树做成了用户控件,想把一棵树的状态传到另一个页面,比方说一个根结点是打开的,我想在跳转到另一个页面时也是打开的,又应该怎么做呢,请各位朋友帮忙,谢谢了,很急!

解决方案 »

  1.   

    using System;
    using System.Drawing;
    using Microsoft.Web.UI.WebControls;namespace RunTimeWebControls
    {
    /// <summary>
    /// Summary description for WebTreeView.
    /// </summary>
    [ToolboxBitmap(typeof(System.Windows.Forms.TreeView))]
    public class WebTreeView:TreeView 
    {
    public WebTreeView()
    {
    this.SystemImagesPath = "/webctrl_client/1_0/treeimages/";
    this.AutoPostBack = true;
    this.AutoSelect = true;
    this.ShowLines=true;
    this.ShowPlus = true;
    this.BorderWidth=2;
    this.BorderStyle = System.Web.UI.WebControls.BorderStyle.Inset;
    }

    public void ExpandAll()
    {
    foreach (TreeNode loNode in this.Nodes)
    {
    ExpandChild(loNode);
    }
    } public TreeNode GetSelectedNode()
    {
    return this.GetNodeFromIndex(this.SelectedNodeIndex);
    } public static void ExpandChild(TreeNode poNode)
    {
    if (poNode!=null&&poNode.Nodes.Count>0)
    {
    poNode.Expanded = true;
    foreach (TreeNode loNode in poNode.Nodes)
    ExpandChild(loNode);
    }
    }
    }
    }这个是我用的时候简单封装了一下,也许你有点启示。
      

  2.   

    loNode.GetNodeIndex();  可以得到当前这个TreeNode对象的位置,你可以遍历,把所有展开的TreeNode的位置Index传到另外一个页面去,在把这些Node打开来。