TreeView - select a node ???

Discussion in 'ASP .Net Web Controls' started by Guest, Sep 27, 2003.

  1. Guest

    Guest 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.
     
    Guest, Sep 27, 2003
    #1
    1. Advertising

  2. 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.
     
    Tian Min Huang, Sep 29, 2003
    #2
    1. Advertising

  3. Jagdish Sakhiya, Apr 9, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wolf
    Replies:
    0
    Views:
    569
  2. Replies:
    0
    Views:
    1,620
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,484
    Dimitre Novatchev
    Aug 24, 2006
  4. jiing
    Replies:
    0
    Views:
    2,383
    jiing
    Apr 27, 2007
  5. Homer J. Simpson

    TreeView node style - for an individual node

    Homer J. Simpson, Jul 23, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    8,954
    Homer J. Simpson
    Jul 24, 2007
Loading...

Share This Page