Hi,

I have a tree view in which there are two child nodes with parentID 0 and a main node with no ID.

Root Node
0--> Child 1
------1--> SubChilds
------------3--->SubChild1
------1--> Subchilds
0--> Child 2
------2--> SubChilds
------2--> SubChilds

The tree structure is as above. The problem is that whenever I click on Child 2 the Child 1 node gets expanded, I have checked using breakpoints and found out that whenever I click on Child 2 the sleectednode.text shows Child 1. How can I clear this?

Thank & Regards,
SaJ

Recommended Answers

All 3 Replies

SaJiN welcome to DaniWeb! :)
We could probably clear this this if you would send us a piece of the rlevant code.

Hi,

Treeview1_SelectedNodeChanged()
{
Datatable dt = //Treeview binding
ds.tables.add(dt);
TreeNode selectedNode = New TreeNode();
selectedNode = this.Treeview1.SelectedNode.Text;
}

Here selectedNode always shows the text of the first Child node even if I click on the second Child Node. I am binding the tree from the SQL table using a datatable.

Thanks & Regards,
SaJ

PageLoad()
{
(!IsPostBack)
{
this.GetParentNodes();
}
}

public void GetParentNodes()
{
try
{
TreeNode topNode = New TreeNode();
topNode.Text = "Reference Document";
topNode.Value = "0";
topNode.SelectAction = TreeNodeSelectAction.SelectExpand();
topNode.CollapseAll();
TreeView1.Nodes.Add(topNode);
DataTable dt = obj.SelectDocument("DocumentId");
ds.Tables.Add(dt);
ds.Relations.Add("ChildRow",ds.Tables[0]Columns["Id"],ds.Tables[0]Columns["ParentId"],
false);
foreach(DataRow firstDataRows in ds.Tables[0]Rows)
{
if(Convert.toInt32(firstDataRows["ParentId"] == 0)
{
TreeNode parentTreeNode = New TreeNode();
parentTreeNode.Text = firstDataRows["FolderName"].ToString();
parentTreeNode.Value = firstDataRows["ParentId"].ToString();
parentTreeNode.SelectAction = TreeNodeSelection.SelectExpand();
parentTreeNode.CollapseAll();
parentTreeNode.Selected = True;
topNode.ChildNodes.Add(parentTreeNode);
GetChildNodes(firstDataRows,parentTreeNode);
}

This is what I have given for tree view binding

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.