TreeView - select a node ???

G

Guest

Hi,

I'm using the IE TreeView WebControl in my ASP.NET web application.

How can I upon selecting a tree node, gets its details such Text and
NodeData properties and displaying them? The following illustrates what I
want to achieve:

private void TreeView1_SelectedIndexChange(object sender,
Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs e)
{
this.Label1.Text = e.[I want the selected node's Text or NodeData
here!]
}

Any ideas ???

Thanks,
Steve.
 
T

Tian Min Huang

Hello Steve,

Thanks for your post. I'd like to share the following information with you:

The TreeViewSelectEventArgs have two properties, NewNode and OldNode, which
are Strings represent the indexes of the selected node and previouse
selected node respectively. If the node is under the root, its value will
be a number say, NewNode == "1". While its under sub folders, each sub
folder index will be separated by '.' in the string, for example, NewNode
== "1.3.2.0". I wrote the following code to find the TreeNode according to
the given NewNode string. Please refer to it:

//-----------------------code snippet------------------------
private void TreeView1_SelectedIndexChange(object sender,
Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs e)
{
Microsoft.Web.UI.WebControls.TreeNode node = null;
string delimStr = ".";
char [] delimiter = delimStr.ToCharArray();
string [] split = null;

split = e.NewNode.Split(delimiter, 100);
foreach (string s in split)
{
if(node == null)
node = TreeView1.Nodes[int.Parse(s)];
else
node = node.Nodes[int.Parse(s)];
}

// now that we get the newly selected node
Label1.Text = node.Text;
}
//---------------------end of-------------------------

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top