Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net Treeview issue (can't get child nodes to display)

I have been working on this for a while, but cannot resolve the issue. I have searched S/O & Google, but no luck. Hoping someone on here can help resolve this.

I am not able to display the child nodes in my TreeView control. The data is being retrieved from a database.
The root node appears fine, but there are not child nodes displayed. How can I get the child nodes to be displayed?

My code is:

private void PopulateTreeNode(DataSet dsList)
{
    var treeNode = new TreeNode();
    foreach (DataRow dr in dsList.Tables[0].Rows)
    {
        if (dr["RecordTypeID"].ToString() == "1")
        {
            TreeNode NewNode = new TreeNode(dr["CustomerName"].ToString(), dr["customerID"].ToString());
            treeCustomer.Nodes.Add(NewNode);
        }
        else if (dr["RecordTypeID"].ToString() == "2")
        {
            TreeNode pNode = new TreeNode(dr["CustomerName"].ToString(), dr["customerID"].ToString());
            pNode.ChildNodes.Add(pNode);
        }
        else if (dr["RecordTypeID"].ToString() == "3")
        {
            TreeNode pNode = new TreeNode(dr["CustomerName"].ToString(), dr["customerID"].ToString());
            pNode.ChildNodes.Add(pNode);
        }
    }
    treeCustomer.Nodes.Add(treeNode);
    treeCustomer.DataBind();
}
like image 971
DNR Avatar asked Jan 24 '26 21:01

DNR


1 Answers

You don't need to call treeCustomer.DataBind() if you are manually adding nodes like this. It is probably clearing out your tree.

like image 134
d89761 Avatar answered Jan 27 '26 09:01

d89761



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!