Posts
6
Comments
20
Trackbacks
0
ASP.Net TreeView - scroll to the selected node
Technorati Tags: ,,

If we have TreeView inside of the div with the fixed width and height we want selected node to be visible after postback.

Here is small JavaScript function that does this (you don’t have to use jQuery as I did to get the result):

   1:          function ScrollToSelectedNode()
   2:          {
   3:              //* get selected node id
   4:              //* 'tvwScrollTo' - is our tree view id
   5:              var selectedNodeID = $('#<%=tvwScrollTo.ClientID %>_SelectedNode').val();
   6:   
   7:              if (selectedNodeID != '')
   8:              {
   9:                  //* calculate selected top an left position (http://docs.jquery.com/CSS/position)
  10:                  //* in order to get correct relative position remember to set div position to absolute
  11:                  var scrollTop = $('#' + selectedNodeID).position().top;
  12:                  var scrollLeft = $('#' + selectedNodeID).position().left;
  13:                  
  14:                  //* here 'divTreeViewScrollTo' is the id of the div where we put our tree view
  15:                  $('#divTreeViewScrollTo').scrollTop(scrollTop);
  16:                  $('#divTreeViewScrollTo').scrollLeft(scrollLeft);
  17:              }
  18:          }

Run this function on postback:

   1:          protected void tvwScrollTo_SelectedNodeChanged(object sender, EventArgs e)
   2:          {
   3:              ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ScrollToSelectedNode", "ScrollToSelectedNode();", true);
   4:          }

Result before node selected and after:

TreeView_NodeSelect TreeView_NodeSelect_AfterPostback

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Wednesday, January 27, 2010 12:25 AM Print
Comments
Gravatar
# re: ASP.Net TreeView - scroll to the selected node
Luis Vega
7/11/2011 1:14 PM
I'm having the selected node problem and 'im trying to use your script but when i run it, throws me the next error:

Microsoft JScript: Syntax error, unrecognized expression: #[object Object]

Do you have and idea of whats going on?

Thanks
Gravatar
# re: ASP.Net TreeView - scroll to the selected node
Luis Vega
7/13/2011 11:23 AM
is there a way to get the correct relative position without setting the div to absolute?
Gravatar
# re: ASP.Net TreeView - scroll to the selected node
gamebacker
10/18/2011 3:28 AM
If the PlayStation 3 feels extremely hot or the system will power off and the power light flashes red, this could be an indicator there is a temperature issue with the pink ps3 controller dualshock and it is not able to keep the system cool. Please attempt the following troubleshooting steps.
Gravatar
# re: ASP.Net TreeView - scroll to the selected node
wordpress website hosting
12/18/2011 5:48 AM
yes,you have solved the problems confused me for a long time,before,I can not handle the issue related with ASP.NET TreeView jQuery
Gravatar
# re: ASP.Net TreeView - scroll to the selected node
wordpress website hosting
12/18/2011 5:50 AM
YES,YOU HAVE SOLVED THE PROBLEM CONFUSED FOR A LONG TIME,before,I am not well in the handling with jquery coding
Gravatar
# re: ASP.Net TreeView - scroll to the selected node
wordpress website hosting
12/18/2011 5:50 AM
YES,YOU HAVE SOLVED THE PROBLEM CONFUSED FOR A LONG TIME,before,I am not well in the handling with jquery coding

Post Comment

Title *
Name *
Email
Url
Comment *  
 
Tag Cloud