Maintain Tree View State

Discussion in 'ASP .Net' started by Andrew Robinson, Jan 11, 2006.

  1. I have a treeview control that I use as a menu & navigation control within a
    master page. The nodes for this control are loaded from a database which
    contains the text and url of each like and the hierarchy of the menu tree.
    All pretty normal stuff.

    Is there any simple method of maintaining the expanded / collapsed state of
    each node as my application moves from page to page? Remember this is on a
    master page used by numerous content pages.

    I am looking for something obvious that I might be missing.

    I do have two solutions that are coded and work but wondering if there is
    something better?

    1. Clone the entire control and put it in Session or Cache.
    2. Build a Dictionary based on the path at each node and the state of each
    node. Put the dictionary in Session or Cache.

    Thanks,
    Andrew Robinson, Jan 11, 2006
    #1
    1. Advertising

  2. Andrew,

    I would make a simple array of which node numbers are expanded and assume
    all others are collapsed and store that list in viewstate (an arraylist
    would work nicely). Then you can have the master page store fill out and
    store to viewstate the arraylist and retrieve it each time the master page
    loads the tree again.

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Andrew Robinson" <> wrote in message
    news:...
    >I have a treeview control that I use as a menu & navigation control within
    >a master page. The nodes for this control are loaded from a database which
    >contains the text and url of each like and the hierarchy of the menu tree.
    >All pretty normal stuff.
    >
    > Is there any simple method of maintaining the expanded / collapsed state
    > of each node as my application moves from page to page? Remember this is
    > on a master page used by numerous content pages.
    >
    > I am looking for something obvious that I might be missing.
    >
    > I do have two solutions that are coded and work but wondering if there is
    > something better?
    >
    > 1. Clone the entire control and put it in Session or Cache.
    > 2. Build a Dictionary based on the path at each node and the state of each
    > node. Put the dictionary in Session or Cache.
    >
    > Thanks,
    >
    >
    S. Justin Gengo [MCP], Jan 11, 2006
    #2
    1. Advertising

  3. Justin,

    Thanks. Basically number 2 that I listed.


    "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote in
    message news:...
    > Andrew,
    >
    > I would make a simple array of which node numbers are expanded and assume
    > all others are collapsed and store that list in viewstate (an arraylist
    > would work nicely). Then you can have the master page store fill out and
    > store to viewstate the arraylist and retrieve it each time the master page
    > loads the tree again.
    >
    > --
    > Sincerely,
    >
    > S. Justin Gengo, MCP
    > Web Developer / Programmer
    >
    > www.aboutfortunate.com
    >
    > "Out of chaos comes order."
    > Nietzsche
    > "Andrew Robinson" <> wrote in message
    > news:...
    >>I have a treeview control that I use as a menu & navigation control within
    >>a master page. The nodes for this control are loaded from a database which
    >>contains the text and url of each like and the hierarchy of the menu tree.
    >>All pretty normal stuff.
    >>
    >> Is there any simple method of maintaining the expanded / collapsed state
    >> of each node as my application moves from page to page? Remember this is
    >> on a master page used by numerous content pages.
    >>
    >> I am looking for something obvious that I might be missing.
    >>
    >> I do have two solutions that are coded and work but wondering if there is
    >> something better?
    >>
    >> 1. Clone the entire control and put it in Session or Cache.
    >> 2. Build a Dictionary based on the path at each node and the state of
    >> each node. Put the dictionary in Session or Cache.
    >>
    >> Thanks,
    >>
    >>

    >
    >
    Andrew Robinson, Jan 11, 2006
    #3
  4. Yep. :) But I wanted to make certain that you saw viewstate as an option. I
    like to store some things client side when I can. As long as it isn't a
    great deal of information it is still just as fast for the customer and it
    keeps the server as lean as possible.

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Andrew Robinson" <> wrote in message
    news:...
    > Justin,
    >
    > Thanks. Basically number 2 that I listed.
    >
    >
    > "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote
    > in message news:...
    >> Andrew,
    >>
    >> I would make a simple array of which node numbers are expanded and assume
    >> all others are collapsed and store that list in viewstate (an arraylist
    >> would work nicely). Then you can have the master page store fill out and
    >> store to viewstate the arraylist and retrieve it each time the master
    >> page loads the tree again.
    >>
    >> --
    >> Sincerely,
    >>
    >> S. Justin Gengo, MCP
    >> Web Developer / Programmer
    >>
    >> www.aboutfortunate.com
    >>
    >> "Out of chaos comes order."
    >> Nietzsche
    >> "Andrew Robinson" <> wrote in message
    >> news:...
    >>>I have a treeview control that I use as a menu & navigation control
    >>>within a master page. The nodes for this control are loaded from a
    >>>database which contains the text and url of each like and the hierarchy
    >>>of the menu tree. All pretty normal stuff.
    >>>
    >>> Is there any simple method of maintaining the expanded / collapsed state
    >>> of each node as my application moves from page to page? Remember this is
    >>> on a master page used by numerous content pages.
    >>>
    >>> I am looking for something obvious that I might be missing.
    >>>
    >>> I do have two solutions that are coded and work but wondering if there
    >>> is something better?
    >>>
    >>> 1. Clone the entire control and put it in Session or Cache.
    >>> 2. Build a Dictionary based on the path at each node and the state of
    >>> each node. Put the dictionary in Session or Cache.
    >>>
    >>> Thanks,
    >>>
    >>>

    >>
    >>

    >
    >
    S. Justin Gengo [MCP], Jan 11, 2006
    #4
  5. Justin,

    I am back to my original solution on this one.

    1. ViewState is not maintained between two different pages. You need to save
    you state in either Session or the Server Cache. Remember that I am using
    this within a Master Page that is used on multiple content pages.

    2. Is there some type of Node ID or number that can be used as a key for
    each node? I am currently recursively walking the node tree and just using
    an index that is external to the nodes that I add to. I don't think that you
    can use the Data or Value path because there is no guarantee that it will
    generate a unique key.

    Thanks,

    -Andrew



    "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote in
    message news:%231R%...
    > Yep. :) But I wanted to make certain that you saw viewstate as an option.
    > I like to store some things client side when I can. As long as it isn't a
    > great deal of information it is still just as fast for the customer and it
    > keeps the server as lean as possible.
    >
    > --
    > Sincerely,
    >
    > S. Justin Gengo, MCP
    > Web Developer / Programmer
    >
    > www.aboutfortunate.com
    >
    > "Out of chaos comes order."
    > Nietzsche
    > "Andrew Robinson" <> wrote in message
    > news:...
    >> Justin,
    >>
    >> Thanks. Basically number 2 that I listed.
    >>
    >>
    >> "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote
    >> in message news:...
    >>> Andrew,
    >>>
    >>> I would make a simple array of which node numbers are expanded and
    >>> assume all others are collapsed and store that list in viewstate (an
    >>> arraylist would work nicely). Then you can have the master page store
    >>> fill out and store to viewstate the arraylist and retrieve it each time
    >>> the master page loads the tree again.
    >>>
    >>> --
    >>> Sincerely,
    >>>
    >>> S. Justin Gengo, MCP
    >>> Web Developer / Programmer
    >>>
    >>> www.aboutfortunate.com
    >>>
    >>> "Out of chaos comes order."
    >>> Nietzsche
    >>> "Andrew Robinson" <> wrote in message
    >>> news:...
    >>>>I have a treeview control that I use as a menu & navigation control
    >>>>within a master page. The nodes for this control are loaded from a
    >>>>database which contains the text and url of each like and the hierarchy
    >>>>of the menu tree. All pretty normal stuff.
    >>>>
    >>>> Is there any simple method of maintaining the expanded / collapsed
    >>>> state of each node as my application moves from page to page? Remember
    >>>> this is on a master page used by numerous content pages.
    >>>>
    >>>> I am looking for something obvious that I might be missing.
    >>>>
    >>>> I do have two solutions that are coded and work but wondering if there
    >>>> is something better?
    >>>>
    >>>> 1. Clone the entire control and put it in Session or Cache.
    >>>> 2. Build a Dictionary based on the path at each node and the state of
    >>>> each node. Put the dictionary in Session or Cache.
    >>>>
    >>>> Thanks,
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    Andrew Robinson, Jan 12, 2006
    #5
  6. Andrew,

    You can expose objects on the master page to the content pages. Just declare
    them as Friend. But you'll certainly have an easier time using session
    because you would then have to code a base content page and inherit it so
    that the code to store the tree in viewstate doesn't have to be repeated on
    each and every page.

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Andrew Robinson" <> wrote in message
    news:%...
    > Justin,
    >
    > I am back to my original solution on this one.
    >
    > 1. ViewState is not maintained between two different pages. You need to
    > save you state in either Session or the Server Cache. Remember that I am
    > using this within a Master Page that is used on multiple content pages.
    >
    > 2. Is there some type of Node ID or number that can be used as a key for
    > each node? I am currently recursively walking the node tree and just using
    > an index that is external to the nodes that I add to. I don't think that
    > you can use the Data or Value path because there is no guarantee that it
    > will generate a unique key.
    >
    > Thanks,
    >
    > -Andrew
    >
    >
    >
    > "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote
    > in message news:%231R%...
    >> Yep. :) But I wanted to make certain that you saw viewstate as an option.
    >> I like to store some things client side when I can. As long as it isn't a
    >> great deal of information it is still just as fast for the customer and
    >> it keeps the server as lean as possible.
    >>
    >> --
    >> Sincerely,
    >>
    >> S. Justin Gengo, MCP
    >> Web Developer / Programmer
    >>
    >> www.aboutfortunate.com
    >>
    >> "Out of chaos comes order."
    >> Nietzsche
    >> "Andrew Robinson" <> wrote in message
    >> news:...
    >>> Justin,
    >>>
    >>> Thanks. Basically number 2 that I listed.
    >>>
    >>>
    >>> "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com>
    >>> wrote in message news:...
    >>>> Andrew,
    >>>>
    >>>> I would make a simple array of which node numbers are expanded and
    >>>> assume all others are collapsed and store that list in viewstate (an
    >>>> arraylist would work nicely). Then you can have the master page store
    >>>> fill out and store to viewstate the arraylist and retrieve it each time
    >>>> the master page loads the tree again.
    >>>>
    >>>> --
    >>>> Sincerely,
    >>>>
    >>>> S. Justin Gengo, MCP
    >>>> Web Developer / Programmer
    >>>>
    >>>> www.aboutfortunate.com
    >>>>
    >>>> "Out of chaos comes order."
    >>>> Nietzsche
    >>>> "Andrew Robinson" <> wrote in message
    >>>> news:...
    >>>>>I have a treeview control that I use as a menu & navigation control
    >>>>>within a master page. The nodes for this control are loaded from a
    >>>>>database which contains the text and url of each like and the hierarchy
    >>>>>of the menu tree. All pretty normal stuff.
    >>>>>
    >>>>> Is there any simple method of maintaining the expanded / collapsed
    >>>>> state of each node as my application moves from page to page? Remember
    >>>>> this is on a master page used by numerous content pages.
    >>>>>
    >>>>> I am looking for something obvious that I might be missing.
    >>>>>
    >>>>> I do have two solutions that are coded and work but wondering if there
    >>>>> is something better?
    >>>>>
    >>>>> 1. Clone the entire control and put it in Session or Cache.
    >>>>> 2. Build a Dictionary based on the path at each node and the state of
    >>>>> each node. Put the dictionary in Session or Cache.
    >>>>>
    >>>>> Thanks,
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    S. Justin Gengo [MCP], Jan 12, 2006
    #6
  7. Hi Justin,

    For your #2 question, I think you can consider idenitfy TreeView's Nodes
    through NodePath, you can find that TreeView control itself has the
    FindNode method which used a certain TreeNode path to find a TreeNode...
    This can help you storing Node info in Session or other global wide
    storage...

    #TreeView.FindNode
    http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.
    findnode.aspx

    Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    --------------------
    | From: "Andrew Robinson" <>
    | References: <>
    <>
    <>
    <#1R#>
    | Subject: Re: Maintain Tree View State
    | Date: Thu, 12 Jan 2006 09:07:13 -0800
    | Lines: 95
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
    | X-RFC2646: Format=Flowed; Response
    | Message-ID: <#>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | NNTP-Posting-Host: 216.57.203.121
    | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
    | Xref: TK2MSFTNGXA02.phx.gbl
    microsoft.public.dotnet.framework.aspnet:370383
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | Justin,
    |
    | I am back to my original solution on this one.
    |
    | 1. ViewState is not maintained between two different pages. You need to
    save
    | you state in either Session or the Server Cache. Remember that I am using
    | this within a Master Page that is used on multiple content pages.
    |
    | 2. Is there some type of Node ID or number that can be used as a key for
    | each node? I am currently recursively walking the node tree and just
    using
    | an index that is external to the nodes that I add to. I don't think that
    you
    | can use the Data or Value path because there is no guarantee that it will
    | generate a unique key.
    |
    | Thanks,
    |
    | -Andrew
    |
    |
    |
    | "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com> wrote
    in
    | message news:%231R%...
    | > Yep. :) But I wanted to make certain that you saw viewstate as an
    option.
    | > I like to store some things client side when I can. As long as it isn't
    a
    | > great deal of information it is still just as fast for the customer and
    it
    | > keeps the server as lean as possible.
    | >
    | > --
    | > Sincerely,
    | >
    | > S. Justin Gengo, MCP
    | > Web Developer / Programmer
    | >
    | > www.aboutfortunate.com
    | >
    | > "Out of chaos comes order."
    | > Nietzsche
    | > "Andrew Robinson" <> wrote in message
    | > news:...
    | >> Justin,
    | >>
    | >> Thanks. Basically number 2 that I listed.
    | >>
    | >>
    | >> "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate.com>
    wrote
    | >> in message news:...
    | >>> Andrew,
    | >>>
    | >>> I would make a simple array of which node numbers are expanded and
    | >>> assume all others are collapsed and store that list in viewstate (an
    | >>> arraylist would work nicely). Then you can have the master page store
    | >>> fill out and store to viewstate the arraylist and retrieve it each
    time
    | >>> the master page loads the tree again.
    | >>>
    | >>> --
    | >>> Sincerely,
    | >>>
    | >>> S. Justin Gengo, MCP
    | >>> Web Developer / Programmer
    | >>>
    | >>> www.aboutfortunate.com
    | >>>
    | >>> "Out of chaos comes order."
    | >>> Nietzsche
    | >>> "Andrew Robinson" <> wrote in message
    | >>> news:...
    | >>>>I have a treeview control that I use as a menu & navigation control
    | >>>>within a master page. The nodes for this control are loaded from a
    | >>>>database which contains the text and url of each like and the
    hierarchy
    | >>>>of the menu tree. All pretty normal stuff.
    | >>>>
    | >>>> Is there any simple method of maintaining the expanded / collapsed
    | >>>> state of each node as my application moves from page to page?
    Remember
    | >>>> this is on a master page used by numerous content pages.
    | >>>>
    | >>>> I am looking for something obvious that I might be missing.
    | >>>>
    | >>>> I do have two solutions that are coded and work but wondering if
    there
    | >>>> is something better?
    | >>>>
    | >>>> 1. Clone the entire control and put it in Session or Cache.
    | >>>> 2. Build a Dictionary based on the path at each node and the state
    of
    | >>>> each node. Put the dictionary in Session or Cache.
    | >>>>
    | >>>> Thanks,
    | >>>>
    | >>>>
    | >>>
    | >>>
    | >>
    | >>
    | >
    | >
    |
    |
    |
    Steven Cheng[MSFT], Jan 13, 2006
    #7
    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. Varangian
    Replies:
    2
    Views:
    7,661
    Varangian
    Mar 17, 2006
  2. Stub

    B tree, B+ tree and B* tree

    Stub, Nov 12, 2003, in forum: C Programming
    Replies:
    3
    Views:
    10,094
  3. raki
    Replies:
    1
    Views:
    1,117
    Alexey Smirnov
    Jun 24, 2009
  4. Rea Peleg

    persisting tree view's state

    Rea Peleg, Jun 3, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    109
    Rea Peleg
    Jun 3, 2004
  5. Parthiv Joshi
    Replies:
    1
    Views:
    649
    Samuel L Matzen
    Jul 6, 2004
Loading...

Share This Page