Expand TreeView programmatically (ASP.NET 2.0)

Discussion in 'ASP .Net' started by Karim El Jed, Oct 5, 2005.

  1. Karim El Jed

    Karim El Jed Guest

    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
    Karim El Jed, Oct 5, 2005
    #1
    1. Advertising

  2. Karim El Jed

    clintonG Guest

    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" <> wrote in message
    news:...
    > 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
    >
    clintonG, Oct 5, 2005
    #2
    1. Advertising

  3. Karim El Jed

    Karim El Jed Guest

    ....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" <> schrieb im
    Newsbeitrag news:%...
    > 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" <> wrote in message
    > news:...
    >> 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
    >>

    >
    >
    Karim El Jed, Oct 6, 2005
    #3
  4. Karim El Jed

    Patirck Ige Guest

    Have you done something similar using treeview v.1.1
    Patrick


    "Karim El Jed" <> wrote in message
    news:%...
    > ...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" <> schrieb im
    > Newsbeitrag news:%...
    > > 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" <> wrote in message
    > > news:...
    > >> 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
    > >>

    > >
    > >

    >
    >
    Patirck Ige, Oct 7, 2005
    #4
  5. Karim El Jed

    Karim El Jed Guest

    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" <> schrieb im Newsbeitrag
    news:...
    > Have you done something similar using treeview v.1.1
    > Patrick
    >
    >
    > "Karim El Jed" <> wrote in message
    > news:%...
    >> ...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" <> schrieb im
    >> Newsbeitrag news:%...
    >> > 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" <> wrote in message
    >> > news:...
    >> >> 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
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
    Karim El Jed, Oct 7, 2005
    #5
    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. Stephen
    Replies:
    2
    Views:
    10,616
    Stephen
    Aug 24, 2005
  2. vivek
    Replies:
    2
    Views:
    6,220
    pushp
    Jun 14, 2007
  3. Anders
    Replies:
    0
    Views:
    858
    Anders
    Apr 27, 2006
  4. sekhar2cool
    Replies:
    0
    Views:
    764
    sekhar2cool
    Apr 14, 2008
  5. Karim El Jed

    Expand TreeView programmatically (ASP.NET 2.0)

    Karim El Jed, Oct 6, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    383
    Karim El Jed
    Oct 6, 2005
Loading...

Share This Page