I just accomplished this. Believe me, it isn't easy. You have to:
Create a class that extends from TreeNode and override the RenderPreText
method
In this method, add code to insert a new anchor tag with an identifiable id
a la
writer.WriteBeginTag("a");
writer.WriteAttribute("id", "a" + this.ValuePath);
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
Create a class that extends from TreeView and override the CreateNode method
In this method, add code that returns an instance of your new TreeNode class
(here called AdvTreeNode)
protected override TreeNode CreateNode()
{
return new AdvTreeNode(this, false);
}
Having done this, you can now create a javascript method (let's call it
scrollTo) that will scroll to this anchor tag: "scrollTo('a" + node.ValuePath
+ "');"
You can register this as a client startup script at the page level by using:
ClientScript.RegisterStartupScript(this.GetType(),
"scrollTo", "scrollTo(\"a" + selected.ValuePath + "\");", true);
"Claus" wrote:
Hello,
I have a long treeview with scrollbars. When I scroll down and press a treeview node, then the Load event fires and navigate in an iframe to another page. The problem is, that afterwards the treeview is collapsed and the node isn't selected. Expanding and selecting the node via code in the load event works, but how do I achieve, that the treeview scrolls down to the selected node?
Thanks for any help
Claus