How to find node in TreeView by using string(the same as Node.Text) ?

Discussion in 'ASP .Net' started by jiing, Apr 27, 2007.

  1. jiing

    jiing Guest

    Hi all,

    I want to use sting(the same as Node.Text) to judge if a node exists
    in TreeView.
    I've tried several ways, but seems all failed.

    could anybody help me?

    Thanks in advance.
    //My TreeView is defined to has depth =3 only.
    //My code snippet as follows:
    // path ="rootNode: parentNode: childNode" // path is something like
    this
    //try to use the path we already have to judge if a node already
    exists in treeveiw

    TreeNode rootNode = new TreeNode();
    TreeNode parentNode = new TreeNode();
    TreeNode childNode = new TreeNode();
    for(int depth = 0 ; depth < path.Length -1; depth+
    +)
    {
    string nodeOfTreeView = path[depth]; //to get the
    rootNode, if depth ==0
    if ( nodeOfTreeView != null) //to prevent some path
    only has depth =2 or 1
    {
    if (depth == 0) //deal with rootNode
    {
    rootNode.Text = nodeOfTreeView;
    rootNode.Value = nodeOfTreeView;
    rootNode.NavigateUrl = @"./
    ShowComponentDetails.aspx?Name=" + nodeOfTreeView;
    if
    (TreeViewOfPath.FindNode(rootNode.ValuePath) != null) //is this
    corrent??
    {
    // Indicate that the node was found.
    showMsg("The specified node (" +
    rootNode.ValuePath + ") was found.");
    }
    else
    {
    // Indicate that the node is not in the
    TreeView control.
    showMsg("The specified node (" +
    nodeOfTreeView + ") is not in this TreeView control.");
    showMsg("new rootNode =" +
    rootNode.Value);

    TreeViewOfPath.Nodes.Add(rootNode);
    }
    }
    else if (depth == 1)
    {
    parentNode.Text = nodeOfTreeView;
    parentNode.Value = nodeOfTreeView;
    parentNode.NavigateUrl = @"./
    ShowComponentDetails.aspx?Name=" + parentNode;

    if (isNodeExistInTreeView(parentNode.Text))
    {
    // Indicate that the node was found.
    showMsg("The specified node (" +
    parentNode.ValuePath + ") was found.");
    }
    else
    {
    // Indicate that the node is not in the
    TreeView control.
    showMsg("The specified node (" +
    nodeOfTreeView + ") is not in this TreeView control.");
    showMsg(" rootNode =" + rootNode.Text);
    showMsg("new parentNode =" +
    parentNode.Value);

    rootNode.ChildNodes.Add(parentNode);
    }



    }
    else if(depth == 2)
    {
    childNode.Text = nodeOfTreeView;
    childNode.Value = nodeOfTreeView;
    childNode.NavigateUrl = @"./
    ShowComponentDetails.aspx?Name=" + childNode;


    if (isNodeExistInTreeView(childNode.Text))
    {
    // Indicate that the node was found.
    showMsg("The specified node (" +
    childNode.ValuePath + ") was found.");
    }
    else
    {
    // Indicate that the node is not in the
    TreeView control.
    showMsg("The specified node (" +
    nodeOfTreeView + ") is not in this TreeView control.");
    showMsg(" parentNode =" +
    parentNode.Text);
    showMsg("new childNode =" +
    childNode.Text);

    parentNode.ChildNodes.Add(childNode);
    }
    }
    }
    //add the treeview we generated to page's form1

    Page.FindControl("Form1").Controls.Add(TreeViewOfPath);
    }
    */
    jiing, Apr 27, 2007
    #1
    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:
    550
  2. =?Utf-8?B?VHltYm93?=
    Replies:
    2
    Views:
    24,451
    =?Utf-8?B?VHltYm93?=
    Jan 10, 2006
  3. Elton Pruitt
    Replies:
    2
    Views:
    5,800
    akjoshi
    Jun 12, 2006
  4. Tjerk Wolterink
    Replies:
    2
    Views:
    1,419
    Dimitre Novatchev
    Aug 24, 2006
  5. Manoj
    Replies:
    0
    Views:
    547
    Manoj
    Nov 4, 2008
Loading...

Share This Page