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

Treeview Node expand

3 Answers 142 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
naveen veda
Top achievements
Rank 1
naveen veda asked on 26 Feb 2009, 07:30 AM
hi,

i have build a tree based on load on demand method (ie, while expanding the root node only the child nodes are getting populated).

now my problem is,

i want to search the employee node in the treeview.

at first, only one node is there in a treeview. i need to call the node_Expand event every time based on the hierarchy of the employee.

the tree view is adding nodes for the first level.next time it gives nullreference exception.
Ex,
---
AAAA
--BBB
-------B1
-------B2
--CCC
--DDD
-------D1
-------D2
------------D21
--EEE

in the above tree i am going to find D21. first it builds the first level ie, AAA,BBB,CCC,DDD,EEE  without error. the next level D1,D2 also bulit without error.next D2 node expanding time it gives the error.

how can i solve this. how to find the employee.

thanks,
mano.

3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 26 Feb 2009, 10:03 AM
Hello naveen veda,

What is the error?

Can you paste here the relevant code? How exactly do you built the second level?

Sincerely yours,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
naveen veda
Top achievements
Rank 1
answered on 27 Feb 2009, 09:47 AM
Hi,

Within the button click event
~~~~~~~~~~~~~~~~~~~~~~

  
              for (int i = 1; i < strLine.Length - 1; i++)
                {
               Session["treenodeExpand"] = strLine[i].ToString();
               Session["EmpID"] = Laser.App.BLL.bllManager.fn_GetEmpIfromNode(Convert.ToInt32(strLine[i]));
               ManagerTreeView_NodeExpand(sender, new RadTreeNodeEventArgs());

              }

TreeNode Expand Event
~~~~~~~~~~~~~~~~~~~~

protected void ManagerTreeView_NodeExpand(object o, RadTreeNodeEventArgs e)
    {

        try
        {
            Label lblSaveMessage = (Label)(Master.FindControl("SaveMessagelbl"));
            lblSaveMessage.Text = string.Empty;

           

                DataTable dtChildNode = new DataTable();
                dtChildNode = Laser.App.BLL.bllManager.fn_GetChildNodes(Convert.ToInt32(Session["treenodeExpand"].ToString()));

                int iChildCount = 0;
                iChildCount = dtChildNode.Rows.Count;
                foreach (DataRow row in dtChildNode.Rows)
                {
                    RadTreeNode node = new RadTreeNode();
                    node.Text = row["employeename"].ToString();
                    node.Value = row["employeeid"].ToString();

                
                    if (iChildCount > 0)
                    {
                        node.ExpandMode = ExpandMode.ClientSide;
                    }
                  ManagerTreeView.Nodes.FindNodeByValue(Convert.ToString(Session["EmpID"])).Nodes.Add(node);
                
                }
                ManagerTreeView.Nodes.FindNodeByValue(Convert.ToString(Session["EmpID"])).Expanded = true;
                ManagerTreeView.Nodes.FindNodeByValue(Convert.ToString(Session["EmpID"])).ExpandMode = ExpandMode.ClientSide;
             }
Catch(Exception ex)
{
}
}


Error
~~~~
that bold letter line gives me the error  as " Object reference not set with an object"

at first level it adds the node to treeview.
second level it gives me the error.

0
Yana
Telerik team
answered on 27 Feb 2009, 02:12 PM
Hello Naveen,

You cannot add child nodes to a different from the expanded node in OnNodeExpand event handler. 

Kind regards,
Yana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
TreeView
Asked by
naveen veda
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
naveen veda
Top achievements
Rank 1
Yana
Telerik team
Share this question
or