Nodes.Count always 1

2 posts, 0 answers
  1. Reiner Ebel
    Reiner Ebel avatar
    15 posts
    Member since:
    Jul 2009

    Posted 29 Nov 2009 Link to this post

    Hello,
    I create a treeview dynamically in an update panel.

    <asp:UpdatePanel ID="UpdatePanel2" runat="server" onload="UpdatePanel2_Load">  
        <ContentTemplate> 
            <telerik:RadTreeView ID="rtvLayoutListe" runat="server" AutoPostBack="true" Height="450px"   
                Skin="Office2007" OnClientNodeClicking="ClientClickHandler"    
                oncontextmenuitemclick="rtvLayoutListe_ContextMenuItemClick"             
                OnNodeClick="rtvLayoutListe_NodeClick"   
                onclientcontextmenuitemclicking="ContextMenuClicking"   
                onclientnodeclicked="ClientClickedHandler" 
                onclientnodeeditstart="startEdit"   
                onnodeedit="rtvLayoutListe_NodeEdit"   
                OnClientContextMenuShowing="onClientContextMenuShowing" > 
                <ContextMenus> 
                    ...  
                </ContextMenus> 
     
            </telerik:RadTreeView> 
        </ContentTemplate> 
        <Triggers> 
            <asp:AsyncPostBackTrigger ControlID="btnRefresh" /> 
        </Triggers> 
    </asp:UpdatePanel> 

    protected void Page_Load(object sender, EventArgs e)  
    {  
        if (!IsPostBack)  
        {  
            GenerateTreeView();              
        }  

    public void GenerateTreeView()  
    {  
        rtvLayoutListe.Nodes.Clear();  
        layoutsql lsql = new layoutsql();  
        DataSet ds = lsql.GetLayoutsForManager();  
     
        RadTreeNode rootNode = new RadTreeNode("Layouts", "folder-0");  
        rootNode.ImageUrl = "../../images/folder.png";  
        rootNode.ToolTip = "Layouts - Please select a Layout or Container";  
        rootNode.Expanded = true;  
        rootNode.ContextMenuID = "RootMainContextMenu";  
        rtvLayoutListe.Nodes.Add(rootNode);  
     
        foreach (DataRow folderRow in ds.Tables["LayoutFolder"].Rows)  
        {              
            RadTreeNode folderNode = new RadTreeNode(folderRow["LgName"].ToString(),   
                "folder-" + folderRow["lgid"].ToString());  
            folderNode.ImageUrl = "../../images/folder.png";  
            folderNode.ToolTip = "Folder";  
            folderNode.ContextMenuID = "MainContextMenu";  
            rootNode.Nodes.Add(folderNode);  
            foreach (DataRow layoutRow in folderRow.GetChildRows("FolderLayouts"))  
            {  
                RadTreeNode layoutNode = new RadTreeNode(layoutRow["LName"].ToString(),   
                    "layout-" + layoutRow["LID"].ToString());  
                layoutNode.ImageUrl = "../../images/desktop.png";  
                layoutNode.ToolTip = "Layout " + layoutRow["LName"].ToString();  
                layoutNode.ContextMenuID = "LayoutFolderCMenu";  
                folderNode.Nodes.Add(layoutNode);  
                foreach (DataRow containerRow in layoutRow.GetChildRows("LayoutContainers"))  
                {  
                    RadTreeNode containerNode = new RadTreeNode(containerRow["CName"].ToString(),  
                        "container-" + containerRow["CID"].ToString());  
                    containerNode.ImageUrl = "../../images/gif.png";  
                    containerNode.ToolTip = "Layout Container " + containerRow["CName"].ToString();  
                    containerNode.ContextMenuID = "EmptyFolderContextMenu";  
                    layoutNode.Nodes.Add(containerNode);                      
                }  
            }  
              
        }  
          
     
     
        int anzahl = rtvLayoutListe.Nodes.Count;  =====>>>>>> Always 1  
     
        //if (Session["cnewvalue"] != null)  
        //{  
        //    if (int.Parse(Session["cnewvalue"].ToString()) > 0)  
        //    {  
        //        foreach (RadTreeNode node in rtvLayoutListe.Nodes)  
        //        {  
        //            if (node.Value == tempcontainer)  
        //            {  
        //                node.Selected = true;  
        //                node.Expanded = true;  
        //            }  
        //            else  
        //            {  
        //                node.Selected = false;  
        //            }  
        //        }  
        //    }  
        //}  

    I get always 1 here: int anzahl = rtvLayoutListe.Nodes.Count;

    Reiner
  2. Roland
    Roland avatar
    156 posts
    Member since:
    Feb 2009

    Posted 29 Nov 2009 Link to this post

    Hello,

    The reason that node count is 1 is because you are adding only 1 node as a root node:

     RadTreeNode rootNode = new RadTreeNode("Layouts""folder-0");   
        rootNode.ImageUrl = "../../images/folder.png";   
        rootNode.ToolTip = "Layouts - Please select a Layout or Container";   
        rootNode.Expanded = true;   
        rootNode.ContextMenuID = "RootMainContextMenu";   
        rtvLayoutListe.Nodes.Add(rootNode);   

    To get all nodes count you can do:

    rtvLayoutList.GetAllNodes().Count 



  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top