Expand TreeView programmatically (ASP.NET 2.0)

K

Karim El Jed

Hi,

I'm trying to expand a special Node of my TreeView from Codebehind.
I have a TreeView on a page for navigating to another site. On the other
tsite here is the same TreeView more precisely a new TreeView with the same
nodes ;)
So I would like to keep the expanding state of the first Tree for the second
one on the next page. At least the last selected node (path will be saved in
query string) should be expanded.

Remarks: The TreeView is rendered in an IFrame to enable scrolling. Maybe
there might be another solution. Let me know if someone knows ;)

Here is what I tried:

protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
//Populate the Tree
TreeView1.Nodes.Add(TopicFactory.PopulateTopicTreeNodes());
TreeView1.Target = "_parent";

if (Request.QueryString["path"] != null)
{
//path for the node is in the query string
string path = Request.QueryString["path"];
TreeNode selected = TreeView1.FindNode(path);

if (selected != null)
{
//expand the node belonging to the given path
selected.Expand();
}
}
}
}

Finding the node is no problem. But it seems the method Expand() has no
effect :(

I hope someone can help.

Greetings

Karim
 
K

Karim El Jed

....no I don't think so. Problem is not to store and get the state of the
tree. Problem is that I cannot tell the Tree to expand a certain node.
This has to work even if the page is loaded for the first time. If I give a
path in the querystring the tree should expand this path.

Any other idea?


clintonG said:
Would this [1] help?
See also...
google: postbackurl site:msdn2.microsoft.com

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/

[1] http://msdn2.microsoft.com/en-us/library/40ybyx3k(en-us,vs.80).aspx



Karim El Jed said:
Hi,

I'm trying to expand a special Node of my TreeView from Codebehind.
I have a TreeView on a page for navigating to another site. On the other
tsite here is the same TreeView more precisely a new TreeView with the
same nodes ;)
So I would like to keep the expanding state of the first Tree for the
second one on the next page. At least the last selected node (path will
be saved in query string) should be expanded.

Remarks: The TreeView is rendered in an IFrame to enable scrolling. Maybe
there might be another solution. Let me know if someone knows ;)

Here is what I tried:

protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
//Populate the Tree
TreeView1.Nodes.Add(TopicFactory.PopulateTopicTreeNodes());
TreeView1.Target = "_parent";

if (Request.QueryString["path"] != null)
{
//path for the node is in the query string
string path = Request.QueryString["path"];
TreeNode selected = TreeView1.FindNode(path);

if (selected != null)
{
//expand the node belonging to the given path
selected.Expand();
}
}
}
}

Finding the node is no problem. But it seems the method Expand() has no
effect :(

I hope someone can help.

Greetings

Karim
 
P

Patirck Ige

Have you done something similar using treeview v.1.1
Patrick


Karim El Jed said:
...no I don't think so. Problem is not to store and get the state of the
tree. Problem is that I cannot tell the Tree to expand a certain node.
This has to work even if the page is loaded for the first time. If I give a
path in the querystring the tree should expand this path.

Any other idea?


clintonG said:
Would this [1] help?
See also...
google: postbackurl site:msdn2.microsoft.com

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/

[1] http://msdn2.microsoft.com/en-us/library/40ybyx3k(en-us,vs.80).aspx



Karim El Jed said:
Hi,

I'm trying to expand a special Node of my TreeView from Codebehind.
I have a TreeView on a page for navigating to another site. On the other
tsite here is the same TreeView more precisely a new TreeView with the
same nodes ;)
So I would like to keep the expanding state of the first Tree for the
second one on the next page. At least the last selected node (path will
be saved in query string) should be expanded.

Remarks: The TreeView is rendered in an IFrame to enable scrolling. Maybe
there might be another solution. Let me know if someone knows ;)

Here is what I tried:

protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
//Populate the Tree
TreeView1.Nodes.Add(TopicFactory.PopulateTopicTreeNodes());
TreeView1.Target = "_parent";

if (Request.QueryString["path"] != null)
{
//path for the node is in the query string
string path = Request.QueryString["path"];
TreeNode selected = TreeView1.FindNode(path);

if (selected != null)
{
//expand the node belonging to the given path
selected.Expand();
}
}
}
}

Finding the node is no problem. But it seems the method Expand() has no
effect :(

I hope someone can help.

Greetings

Karim
 
K

Karim El Jed

No, I didn't. I thought Treeview 1.1 only runs in IE, doesn't it?
I also tried to expand the Treenode before I add it to the Treeview but this
didn't work either.

Karim

Patirck Ige said:
Have you done something similar using treeview v.1.1
Patrick


Karim El Jed said:
...no I don't think so. Problem is not to store and get the state of the
tree. Problem is that I cannot tell the Tree to expand a certain node.
This has to work even if the page is loaded for the first time. If I give a
path in the querystring the tree should expand this path.

Any other idea?


clintonG said:
Would this [1] help?
See also...
google: postbackurl site:msdn2.microsoft.com

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/

[1] http://msdn2.microsoft.com/en-us/library/40ybyx3k(en-us,vs.80).aspx



Hi,

I'm trying to expand a special Node of my TreeView from Codebehind.
I have a TreeView on a page for navigating to another site. On the other
tsite here is the same TreeView more precisely a new TreeView with the
same nodes ;)
So I would like to keep the expanding state of the first Tree for the
second one on the next page. At least the last selected node (path
will
be saved in query string) should be expanded.

Remarks: The TreeView is rendered in an IFrame to enable scrolling. Maybe
there might be another solution. Let me know if someone knows ;)

Here is what I tried:

protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
//Populate the Tree
TreeView1.Nodes.Add(TopicFactory.PopulateTopicTreeNodes());
TreeView1.Target = "_parent";

if (Request.QueryString["path"] != null)
{
//path for the node is in the query string
string path = Request.QueryString["path"];
TreeNode selected = TreeView1.FindNode(path);

if (selected != null)
{
//expand the node belonging to the given path
selected.Expand();
}
}
}
}

Finding the node is no problem. But it seems the method Expand() has
no
effect :(

I hope someone can help.

Greetings

Karim
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top