Get All parents of selected nodes in asp.net 2.0

T

Ted Ngo

Hi All,

I am using treeview control in asp.net 2.0.
this is my treeview:

ZZZZZ
NNNNNN
HHHHHHH
KKKKKKK
AAAA
BBBB
CCCC
DDDD
LLLLL
11111
22222
333333
XXXXX
12345
5678
YYYYY

if I selected "DDDD" node, I would get to get all the parents text of
the "DDDD" node
I want to get back "CCCC", "BBBB", "AAAA"

I am using this to get "DDDD" node text back "tv.SelectedNode.Text"
And I am using this to get "CCCC" node text back
tv.SelectedNode.Parent.Text but I am not sure how to get BBBB and AAAA
text back.

Please help.

Thanks in advance
 
J

John

Hello Ted,

If "DDDD" is selected then:
tv.SelectedNode.Parent.Text returns "CCCC"
tv.SelectedNode.Parent.Parent.Text returns "BBBB"
tv.SelectedNode.Parent.Parent.Parent.Text returns "AAAA"

Is that what you're after?

Best regards

John
 
T

Ted Ngo

Hello Ted,

If "DDDD" isselectedthen:
tv.SelectedNode.Parent.Text returns "CCCC"
tv.SelectedNode.Parent.Parent.Text returns "BBBB"
tv.SelectedNode.Parent.Parent.Parent.Text returns "AAAA"

Is that what you're after?

Best regards

John










- Show quoted text -

Yes, that is what I want, Thanks. But the problem is that the nodes
not always 4 levels, it different from nodes to nodes, I mean some
time it 5 levels, sometime 2, some 10 levels.
So I do it programmaticly.

I try this to get all the values of the nodes selected. (all it
parents)
string tst = tv.selectednodes.valuepath.
now which the values, can I get the nodes text. How.

Thanks
 
J

John

Do you mean:

tv.SelectedNode.FullPath

?

John

Ted Ngo said:
Yes, that is what I want, Thanks. But the problem is that the nodes
not always 4 levels, it different from nodes to nodes, I mean some
time it 5 levels, sometime 2, some 10 levels.
So I do it programmaticly.

I try this to get all the values of the nodes selected. (all it
parents)
string tst = tv.selectednodes.valuepath.
now which the values, can I get the nodes text. How.

Thanks
 
T

Ted Ngo

Do you mean:

tv.SelectedNode.FullPath

?

John









- Show quoted text -


Here is path of my code:

protected void TreeNodeChanged(object sender, EventArgs e)
{
string [] nodepath;
string txt;
string txtofnodeselct;

txtofnodeselct = tv.SelectedNode.Text

txt = "";
nodepath = tv.SelectedNode.ValuePath.Split('/');

Now ny now nodepath have these nodes values:
nodepath[0] = "123"
nodepaht[1] = "456"
nodepath[2] = "893"
nodepath[3] = "442"
and so on

//now I loop through nodepath
foreach (string str in nodepath)
{
//my str will contain the value of the nodes
//How can I get the text of that node which the value node in the
"str"
//Please help.

}

}

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top