This is a migrated thread and some comments may be shown as answers.

I am building treeview dynamically. First it runs correctly. But when i used it in user control after sometime all the events stops to be firing.Please help me out. No events are firing.

1 Answer 75 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
sap
Top achievements
Rank 1
sap asked on 09 Jun 2010, 03:41 PM
protected void Page_Load(object sender, EventArgs e)  
        {  
            try  
            {  
                //Get all parents in hierarchy for the client and set First Level Ultimate ParentDuns  
                ControllerController.NodeUltimateParentsList = Controller.GetClientUltimateParentsList(Controller.ClientId);  
                SetUltimateParentDuns();          
                //TreeView event on expanding any node in tree view  
                t1.NodeExpand += new RadTreeViewEventHandler(t1_NodeExpand);  
                t1.NodeCreated += new RadTreeViewEventHandler(t1_NodeCreated);  
                t1.NodeClick += new RadTreeViewEventHandler(t1_NodeClick);  
                t1.OnClientMouseOver = "ClientMouseOver";  
                  
                  
            }  
            catch (Exception ex)  
            {  
 
            }  
        }  
void t1_NodeClick(object sender, RadTreeNodeEventArgs e)  
        {  
            if (OnNodeClick != null)  
                OnNodeClick(sender, e);  
              
        }  
  public void BindHierarchy()  
        {  
           LoadRootNodes();  
                   }  
void t1_NodeCreated(object sender, RadTreeNodeEventArgs e)  
        {  
 
            RadTreeNode currentNode = e.Node;  
            RadTreeNode parentNode = e.Node.ParentNode;  
            if (currentNode.Value.ToString() != string.Empty)  
            {  
                //If parent not null then set UltimateParent attribute to current node  
                if (parentNode != null)  
                {  
                    currentNode.Attributes.Add("UltimateParent", parentNode.Attributes["DUNSNbr"]);  
                }  
                //Check if current node has DUNSNbr which is current parent in client hierarchy branch then expand and bind it's next level  
                if (currentNode.Value.Trim() != string.Empty && currentNode.Value == UltimateParent && NodeLevel >= 0)  
                {  
                    //First of all set next ultimate parent so that it can be checked for next loop  
                    currentNode.ExpandMode = TreeNodeExpandMode.ClientSide;  
                    SetUltimateParentDuns();  
                    currentNode.Expanded = true;                      
                    BindNextLevelHierarchy(currentNode, currentNode.Value);  
                }  
                else  
                {  
                    currentNode.ExpandMode = NodeExpandMode;  
                }  
            }  
        }  
void t1_NodeExpand(object sender, RadTreeNodeEventArgs e)  
        {  
            try  
            {  
                if (e.Node.Value.Trim() != string.Empty)  
                {  
                    AppendChildNodesOnExpand(e.Node);  
                    t1.DataBind();  
                }  
            }  
            catch (Exception ex)  
            {  
                  
            }  
        }  
 private void LoadRootNodes()  
        {  
            try  
            {  
                bool isHierarchyExist = false;  
                if (!string.IsNullOrEmpty(GlobalUltimateDuns))  
                {  
                    t1.Nodes.Clear();  
                    //Fetch Root node for the GlobalultimateDuns of client  
                    HierarchyNodeDTO globalRootNodeInfo = Controller.GetGlobalUltimateNode(GlobalUltimateDuns);  
 
                    if (globalRootNodeInfo != null)  
                    {  
                        RadTreeNode rootNode = null;  
                        //Add Root Node  
                        rootNode = CreateNewNode(globalRootNodeInfo);                          
                        t1.Nodes.Add(rootNode);  
 
                        //Fetch all child nodes for the root node  
                        IList<HierarchyNodeDTO> lstChildNodes = Controller.GetChildHierarchyNodes(GlobalUltimateDuns);  
                        //Add child nodes to root one by one  
                        if (lstChildNodes != null && lstChildNodes.Count > 0)  
                        {  
                            foreach (HierarchyNodeDTO nodeInfo in lstChildNodes)  
                            {  
                                RadTreeNode node = CreateNewNode(nodeInfo);  
                                t1.Nodes[0].Nodes.Add(node);  
                            }  
                        }  
                        rootNode.ExpandMode = TreeNodeExpandMode.ClientSide;  
                        rootNode.Expanded = true;  
                        t1.DataBind();  
                        isHierarchyExist = true;  
                    }  
                }  
                if (!isHierarchyExist)  
                {  
                    //Bind current client as single root node  
                    RadTreeNode rootNode = CreateNewNode(Controller.ClientToHierarchy);  
                    t1.Nodes.Add(rootNode);  
                    t1.DataBind();  
                }  
            }  
            catch (Exception ex)  
            {  
 
            }  
        }  
private void AppendChildNodesOnExpand(RadTreeNode parentNode)  
        {  
            IList<HierarchyNodeDTO> lstChildNodes = Controller.GetChildHierarchyNodes(parentNode.Value, parentNode.Level);  
            if (lstChildNodes != null && lstChildNodes.Count > 0)  
            {  
                foreach (HierarchyNodeDTO nodeInfo in lstChildNodes)  
                {  
                    RadTreeNode node = CreateNewNode(nodeInfo);  
                    parentNode.Nodes.Add(node);  
                }  
            }  
        }  
 private void BindNextLevelHierarchy(RadTreeNode parentNode, string parentDuns)  
        {  
            IList<HierarchyNodeDTO> lstCurrentChildNodes = Controller.GetChildHierarchyNodes(parentDuns);  
            if (lstCurrentChildNodes != null && lstCurrentChildNodes.Count > 0)  
            {  
                foreach (HierarchyNodeDTO nodeInfo in lstCurrentChildNodes)  
                {  
                    RadTreeNode node = CreateNewNode(nodeInfo);  
                    parentNode.Nodes.Add(node);  
                    //If we get Client node then select it  
                    if (nodeInfo.ClientId == Controller.ClientId)  
                    {  
                        node.Selected = true;  
                        UltimateParent = "";  
                        NodeLevel = -1;  
                    }  
                }  
            }  
        }  
/// <summary> 
        /// AddCustomAttributesToNode  
        /// </summary> 
        /// <param name="attributeInfo"></param> 
        /// <param name="node"></param> 
        private void AddCustomAttributesToNode(HierarchyNodeDTO attributeInfo, RadTreeNode node)  
        {  
            node.Attributes.Add("ClientId", attributeInfo.ClientId.ToString());  
            node.Attributes.Add("CompanyName", attributeInfo.CompanyName);  
            node.Attributes.Add("DUNSNbr", attributeInfo.DUNSNbr);  
            node.Attributes.Add("ParentDuns", attributeInfo.ParentDuns);  
            node.Attributes.Add("GlobalUltimateDuns", attributeInfo.GlobalUltimateDuns);  
            node.Attributes.Add("WLEInd", attributeInfo.WLEInd);  
            node.Attributes.Add("UltimateParent", attributeInfo.UltimateParentInHierarchy);  
        }  
          
        /// <summary> 
        /// CreateNewNode  
        /// </summary> 
        /// <param name="nodeInfo"></param> 
        /// <returns></returns>  
        private RadTreeNode CreateNewNode(HierarchyNodeDTO nodeInfo)  
        {             
            RadTreeNode node = new RadTreeNode();  
            node.Text = nodeInfo.Caption;  
            node.Value = nodeInfo.DUNSNbr;  
            node.ExpandMode = NodeExpandMode;              
            AddCustomAttributesToNode(nodeInfo, node);  
            node.PostBack = true;  
            node.DataBind();  
            return node;  
        }  
 
        /// <summary> 
        /// SetUltimateParentDuns  
        /// </summary> 
        private void SetUltimateParentDuns()  
        {  
            try  
            {  
                //Get ultimate hierarchy                  
                if (Controller.NodeUltimateParentsList != null)  
                {  
                    IList<HierarchyNodeDTO> lstUltimateParents = Controller.NodeUltimateParentsList;  
                    if (lstUltimateParents != null && lstUltimateParents.Count > 0)  
                    {  
 
                        HierarchyNodeDTO ultimateParentDTO = (HierarchyNodeDTO)lstUltimateParents.First(e => e.NodeGeneration == lstUltimateParents.Count-1);  
                        UltimateParent = ultimateParentDTO.DUNSNbr;  
                        NodeLevel = ultimateParentDTO.NodeGeneration;  
                        lstUltimateParents.Remove(ultimateParentDTO);  
                        Controller.NodeUltimateParentsList = lstUltimateParents;  
                    }  
                }  
                else  
                {  
                    UltimateParent = string.Empty;  
                    NodeLevel = -1;  
                }  
            }  
            catch (Exception ex)  
            {  
 
            }  
        } 

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 10 Jun 2010, 03:36 PM
Hello,

Please send us a simple runnable code which will help us reproduce the described issue. Thanks

All the best,
Yana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
TreeView
Asked by
sap
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or