Scroll a node into view -- ASPNET 2.0 Treeview

Discussion in 'ASP .Net Web Controls' started by William Sullivan, Apr 25, 2006.

  1. Anybody figure this out? I can't figure out how to get the node's client
    side control ID in order to grab aholt of it. I've seen a post that says
    that the node's ID is: TreeView.ID + (index of the TreeNode in
    TreeView.Nodes collection). The problem is that, even after a postback, you
    can't get the index of the treenode in the collection. You'd think that this
    would work:
    (after SelectedNodeChanged postback)
    TreeView.Nodes.IndexOf(TreeView.SelectedNode)
    --or--
    (when you have the ValuePath)
    TreeView.Nodes.IndexOf(TreeView.FindNode(ValuePath))

    Both of which return -1 for the node index. So what's the solution?
    William Sullivan, Apr 25, 2006
    #1
    1. Advertising

  2. Placing the solution here for future reference:

    The TreeView creates an object in Javascript on the client side that's called
    [treeview name]_Data
    i.e., if the treeview is named tvNavigation, the object's name would be
    tvNavigation_Data
    This object has a property called selectedNodeID. This property has a ...
    property called value that contains the id of the currently selected node. So

    var name = tvNavigation_Data.selectedNodeID.value;
    var selectedNode =
    Document.all?Document.all[name]:Document.getElementById(name);
    if(selectedNode){ selectedNode.scrollIntoView(true); }

    will scroll the currently selected node into view.


    "William Sullivan" wrote:

    > Anybody figure this out? I can't figure out how to get the node's client
    > side control ID in order to grab aholt of it. I've seen a post that says
    > that the node's ID is: TreeView.ID + (index of the TreeNode in
    > TreeView.Nodes collection). The problem is that, even after a postback, you
    > can't get the index of the treenode in the collection. You'd think that this
    > would work:
    > (after SelectedNodeChanged postback)
    > TreeView.Nodes.IndexOf(TreeView.SelectedNode)
    > --or--
    > (when you have the ValuePath)
    > TreeView.Nodes.IndexOf(TreeView.FindNode(ValuePath))
    >
    > Both of which return -1 for the node index. So what's the solution?
    >
    William Sullivan, Jun 9, 2006
    #2
    1. Advertising

  3. The TreeView creates an object in Javascript on the client side that's called
    [treeview name]_Data
    i.e., if the treeview is named tvNavigation, the object's name would be
    tvNavigation_Data
    This object has a property called selectedNodeID. This property has a ...
    property called value that contains the id of the currently selected node. So

    var name = tvNavigation_Data.selectedNodeID.value;
    var selectedNode =
    Document.all?Document.all[name]:Document.getElementById(name);
    if(selectedNode){ selectedNode.scrollIntoView(true); }

    will scroll the currently selected node into view.

    "William Sullivan" wrote:

    > Anybody figure this out? I can't figure out how to get the node's client
    > side control ID in order to grab aholt of it. I've seen a post that says
    > that the node's ID is: TreeView.ID + (index of the TreeNode in
    > TreeView.Nodes collection). The problem is that, even after a postback, you
    > can't get the index of the treenode in the collection. You'd think that this
    > would work:
    > (after SelectedNodeChanged postback)
    > TreeView.Nodes.IndexOf(TreeView.SelectedNode)
    > --or--
    > (when you have the ValuePath)
    > TreeView.Nodes.IndexOf(TreeView.FindNode(ValuePath))
    >
    > Both of which return -1 for the node index. So what's the solution?
    >
    William Sullivan, Jun 9, 2006
    #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.

Share This Page