none
延迟加载的Treeview选中时背景不变色 RRS feed

  • 问题

  •     public void BuildOuTree(string sPath)
        {
    
            DirectoryEntry RootOu = ADMan.GetDirectoryObject(sPath);
    
            TreeNode RootNode = new TreeNode();
            RootNode.Text = "&nbsp" + RootOu.Name;
            RootNode.Value = RootOu.NativeGuid;
            RootNode.Target = "mmc";
            RootNode.NavigateUrl = "mmc2.aspx?guid=" + RootNode.Value;
            RootNode.PopulateOnDemand = true;
            RootNode.Expanded = false;
            
            if (sPath.ToUpper() == "LDAP://DC=CONTOSO,DC=COM")
            {
                RootNode.ImageUrl = @"~\images\dc.png";
            }
            else
            {
                RootNode.ImageUrl = @"~\images\ou.png";
            }
            OuTree.Nodes.Add(RootNode);
    
            //GetChildNode(RootNode);
        }
        protected void OuTree_TreeNodePopulate(object sender, TreeNodeEventArgs e)
        {
            TreeNode ParentNode = e.Node;
            
            string sPath = ParentNode.Value;
            sPath = "LDAP://<GUID=" + sPath + ">";
            //注意path的处理,必须带上ldap
            ArrayList ChildOus = ADMan.GetChildOus(sPath);
            if (ChildOus.Count > 0)
            {
                foreach (string[] ChildOu in ChildOus)
                {
                    TreeNode ChildNode = new TreeNode();
                    ChildNode.Text = "&nbsp" + ChildOu[1];
                    ChildNode.Value = ChildOu[0];
                    ChildNode.Target = "mmc";
                    ChildNode.NavigateUrl = "mmc2.aspx?guid=" + ChildNode.Value;
                    ChildNode.ImageUrl = @"~\images\ou.png";
                    ChildNode.PopulateOnDemand = true;
                    ChildNode.Expanded = false;
    
                    ParentNode.ChildNodes.Add(ChildNode);
                    //OuTree.Nodes.Add(ChildNode);
    
                    //GetChildNode(ChildNode);
                }
            }
        }

    <asp:TreeView ID="OuTree" runat="server" ExpandDepth="0" ShowLines="True" 
                            LineImagesFolder="~/TreeLineImages" 
                            ontreenodepopulate="OuTree_TreeNodePopulate">
                            <SelectedNodeStyle BackColor="Yellow" BorderColor="#003300" BorderStyle="Solid" 
                                BorderWidth="1px" Font-Italic="True" />
                        </asp:TreeView>

    只有根节点点击后才变色了。各位看下如何改进

    ...

    2013年2月22日 4:51

答案