TreeView

Discussion in 'ASP .Net Web Controls' started by Morris Neuman, Jun 24, 2009.

  1. Hi,

    I have a page with a TreeView. The TreeView contains 2 nodes, each node
    containing several leaf nodes.

    By setting the parent node Expansion to false, the treeview always shows
    un-expanded. If I set expansion to true that it always shows expanded.

    Below is my treeview structure. I want the treeview not to show expanded
    until the user clicks to expand, then I want it to remain expanded until they
    minimize.

    Appreciate your help.
    --
    Thanks
    Morris
    Morris Neuman, Jun 24, 2009
    #1
    1. Advertising

  2. Hi Morris,

    >Below is my treeview structure. I want the treeview not to show expanded
    >until the user clicks to expand, then I want it to remain expanded until

    they
    >minimize.


    I cannot see your TreeView. Is it something like this?

    <asp:TreeView ID="TreeView1" runat="server">
    <Nodes>
    <asp:TreeNode Text="Root" Value="Root">
    <asp:TreeNode Text="Node1" Value="Node1">
    <asp:TreeNode Text="Leaf Node1" Value="Leaf
    Node1"></asp:TreeNode>
    <asp:TreeNode Text="Leaf Node2" Value="Leaf
    Node2"></asp:TreeNode>
    </asp:TreeNode>
    <asp:TreeNode Text="Node2" Value="Node2">
    <asp:TreeNode Text="Leaf Node1" Value="Leaf
    Node1"></asp:TreeNode>
    <asp:TreeNode Text="Leaf Node2" Value="Leaf
    Node2"></asp:TreeNode>
    </asp:TreeNode>
    </asp:TreeNode>
    </Nodes>
    </asp:TreeView>

    If so could you clarify your requirement? I have several different
    understandings according to your above description. To avoid
    misunderstanding you can send me some screenshots and clarify it in detail.
    You can send screenshots to . Please update here after
    sending in case I missed that email.

    Regards,
    Allen Chen
    Microsoft Online Support

    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

    Note: MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 2 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions. Issues of this
    nature are best handled working with a dedicated Microsoft Support Engineer
    by contacting Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Allen Chen [MSFT], Jun 25, 2009
    #2
    1. Advertising

  3. Thanks for the reply.

    I have emailed details to your email as requested.
    --
    Thanks
    Morris


    "Allen Chen [MSFT]" wrote:

    > Hi Morris,
    >
    > >Below is my treeview structure. I want the treeview not to show expanded
    > >until the user clicks to expand, then I want it to remain expanded until

    > they
    > >minimize.

    >
    > I cannot see your TreeView. Is it something like this?
    >
    > <asp:TreeView ID="TreeView1" runat="server">
    > <Nodes>
    > <asp:TreeNode Text="Root" Value="Root">
    > <asp:TreeNode Text="Node1" Value="Node1">
    > <asp:TreeNode Text="Leaf Node1" Value="Leaf
    > Node1"></asp:TreeNode>
    > <asp:TreeNode Text="Leaf Node2" Value="Leaf
    > Node2"></asp:TreeNode>
    > </asp:TreeNode>
    > <asp:TreeNode Text="Node2" Value="Node2">
    > <asp:TreeNode Text="Leaf Node1" Value="Leaf
    > Node1"></asp:TreeNode>
    > <asp:TreeNode Text="Leaf Node2" Value="Leaf
    > Node2"></asp:TreeNode>
    > </asp:TreeNode>
    > </asp:TreeNode>
    > </Nodes>
    > </asp:TreeView>
    >
    > If so could you clarify your requirement? I have several different
    > understandings according to your above description. To avoid
    > misunderstanding you can send me some screenshots and clarify it in detail.
    > You can send screenshots to . Please update here after
    > sending in case I missed that email.
    >
    > Regards,
    > Allen Chen
    > Microsoft Online Support
    >
    > Delighting our customers is our #1 priority. We welcome your comments and
    > suggestions about how we can improve the support we provide to you. Please
    > feel free to let my manager know what you think of the level of service
    > provided. You can send feedback directly to my manager at:
    > .
    >
    > ==================================================
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
    >
    > Note: MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 2 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions. Issues of this
    > nature are best handled working with a dedicated Microsoft Support Engineer
    > by contacting Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
    > ==================================================
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >
    >
    >
    Morris Neuman, Jun 25, 2009
    #3
  4. FYI, the email is being sent by my colleague Jer Mehta.
    --
    Thanks
    Morris


    "Allen Chen [MSFT]" wrote:

    > Hi Morris,
    >
    > >Below is my treeview structure. I want the treeview not to show expanded
    > >until the user clicks to expand, then I want it to remain expanded until

    > they
    > >minimize.

    >
    > I cannot see your TreeView. Is it something like this?
    >
    > <asp:TreeView ID="TreeView1" runat="server">
    > <Nodes>
    > <asp:TreeNode Text="Root" Value="Root">
    > <asp:TreeNode Text="Node1" Value="Node1">
    > <asp:TreeNode Text="Leaf Node1" Value="Leaf
    > Node1"></asp:TreeNode>
    > <asp:TreeNode Text="Leaf Node2" Value="Leaf
    > Node2"></asp:TreeNode>
    > </asp:TreeNode>
    > <asp:TreeNode Text="Node2" Value="Node2">
    > <asp:TreeNode Text="Leaf Node1" Value="Leaf
    > Node1"></asp:TreeNode>
    > <asp:TreeNode Text="Leaf Node2" Value="Leaf
    > Node2"></asp:TreeNode>
    > </asp:TreeNode>
    > </asp:TreeNode>
    > </Nodes>
    > </asp:TreeView>
    >
    > If so could you clarify your requirement? I have several different
    > understandings according to your above description. To avoid
    > misunderstanding you can send me some screenshots and clarify it in detail.
    > You can send screenshots to . Please update here after
    > sending in case I missed that email.
    >
    > Regards,
    > Allen Chen
    > Microsoft Online Support
    >
    > Delighting our customers is our #1 priority. We welcome your comments and
    > suggestions about how we can improve the support we provide to you. Please
    > feel free to let my manager know what you think of the level of service
    > provided. You can send feedback directly to my manager at:
    > .
    >
    > ==================================================
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
    >
    > Note: MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 2 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions. Issues of this
    > nature are best handled working with a dedicated Microsoft Support Engineer
    > by contacting Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
    > ==================================================
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >
    >
    >
    Morris Neuman, Jun 25, 2009
    #4
  5. Hi Morris,

    >FYI, the email is being sent by my colleague Jer Mehta.
    >--
    >Thanks
    >Morris


    Thanks for your update. From the description my understanding is like below:
    " The page is products-cm.aspx
    " On the page there's a TreeView like below:

    <div>
    <h6><a
    href="products-cm.aspx?ViewIndex=1">Features</a></h6>
    <asp:TreeView id="TreeView1" runat="server" NodeIndent="0"
    NodeWrap="True" Width="217px">
    <Nodes>
    <asp:treenode Expanded="True" NavigateUrl="products-cm.aspx?ViewIndex=1"
    SelectAction="SelectExpand" Text="Basic" Value="Basic">
    <asp:treenode Text="Messaging" Value="Messaging"
    NavigateUrl="products-cm.aspx?ViewIndex=5" SelectAction="SelectExpand">
    </asp:treenode>
    <asp:treenode Text="Call Routing" Value="CallRouting"
    NavigateUrl="products-cm.aspx?ViewIndex=6">
    </asp:treenode>
    <asp:treenode Text="IVR/Audiotex" Value="IVRAudiotex"
    NavigateUrl="products-cm.aspx?ViewIndex=7">
    </asp:treenode>
    </asp:treenode>
    <asp:treenode Expanded="True" NavigateUrl="products-cm.aspx?ViewIndex=1"
    SelectAction="SelectExpand" Text="Advanced" Value="Advanced">
    <asp:treenode Text="CALLBasic Scripting" Value="CALLBasic"
    NavigateUrl="products-cm.aspx?ViewIndex=10">
    </asp:treenode>
    <asp:treenode Text="Speech Recognition (ASR)" Value="ASR"
    NavigateUrl="products-cm.aspx?ViewIndex=11">
    </asp:treenode>
    <asp:treenode Text="Text-to-Speech (TTS)" Value="TTS"
    NavigateUrl="products-cm.aspx?ViewIndex=12">
    </asp:treenode>
    </asp:treenode>
    </Nodes>
    <NodeStyle />
    <LeafNodeStyle Font-Size="10px" ForeColor="#333333"
    ImageUrl="customimages/Arrow-Blck.gif" />
    </asp:TreeView>

    </div>

    The expected behavior is:

    " Initially all nodes of the TreeView are collapsed.

    " After clicking any "+" icon to expand node and then click the child node
    to navigate to the same page (with querystring ViewIndex), the expanded
    node must maintain it's state. Namely if it's expanded before navigation it
    must still be expanded after navigation.

    Is my understanding right? If it is, I think you can use following code:

    <div>
    <h6><a href="products-cm.aspx?ViewIndex=1">Features</a></h6>
    <asp:TreeView id="TreeView1" runat="server" NodeIndent="0"
    NodeWrap="True"
    Width="217px" >
    <Nodes>
    <asp:treenode Expanded="True"
    NavigateUrl="javascript:__doPostBack('ViewIndex','1')"
    SelectAction="SelectExpand" Text="Basic" Value="Basic">

    <asp:treenode Text="Messaging" Value="Messaging"
    NavigateUrl="javascript:__doPostBack('ViewIndex','5')"
    SelectAction="SelectExpand">
    </asp:treenode>
    <asp:treenode Text="Call Routing" Value="CallRouting"
    NavigateUrl="javascript:__doPostBack('ViewIndex','6')">
    </asp:treenode>
    <asp:treenode Text="IVR/Audiotex" Value="IVRAudiotex"
    NavigateUrl="javascript:__doPostBack('ViewIndex','7')">
    </asp:treenode>
    </asp:treenode>
    <asp:treenode Expanded="True"
    NavigateUrl="javascript:__doPostBack('ViewIndex','1')"
    SelectAction="SelectExpand" Text="Advanced" Value="Advanced">
    <asp:treenode Text="CALLBasic Scripting" Value="CALLBasic"
    NavigateUrl="javascript:__doPostBack('ViewIndex','10')">
    </asp:treenode>
    <asp:treenode Text="Speech Recognition (ASR)" Value="ASR"
    NavigateUrl="javascript:__doPostBack('ViewIndex','11')">
    </asp:treenode>
    <asp:treenode Text="Text-to-Speech (TTS)" Value="TTS"
    NavigateUrl="javascript:__doPostBack('ViewIndex','12')">
    </asp:treenode>
    </asp:treenode>
    </Nodes>
    <NodeStyle />
    <LeafNodeStyle Font-Size="10px" ForeColor="#333333"
    ImageUrl="customimages/Arrow-Blck.gif" />
    </asp:TreeView>

    </div>


    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack) {
    TreeView1.CollapseAll();
    }
    if (Request.Form["__EVENTTARGET"] == "ViewIndex") {

    if (!String.IsNullOrEmpty(Request.Form["__EVENTARGUMENT"]))
    {
    //test
    Response.Write(Request.Form["__EVENTARGUMENT"]);

    }
    }
    }

    Your original code in aspx uses URL directly. This will cause a get request
    sent to server after the child node is clicked. In this case it's difficult
    to maintain the state of the control. If you have to use get request you
    probably can store the state in session, which is not a good practise to
    store state of control because it consumes server side memory and may
    expire.

    In my above code a post request will be sent to server after you clicking
    the child node. In this case we can benefite from internal mechanism of
    TreeView to maintain the control state during postbacks. As a result of
    this routine we have to use Request.Form["__EVENTTARGET"] to figure out the
    selected "ViewIndex", as shown in my code.

    Regards,
    Allen Chen
    Microsoft Online Support

    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

    Note: MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 2 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions. Issues of this
    nature are best handled working with a dedicated Microsoft Support Engineer
    by contacting Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Allen Chen [MSFT], Jun 26, 2009
    #5
  6. Allen,

    The code worked but did not work. The treeview behaved as I wanted, however
    the navigate urls did not take me to the correct page when clicked. I have
    emailed you the details with an attachment showing the screen behaviour.

    --
    Thanks for your help as always.
    Morris


    "Allen Chen [MSFT]" wrote:

    > Hi Morris,
    >
    > >FYI, the email is being sent by my colleague Jer Mehta.
    > >--
    > >Thanks
    > >Morris

    >
    > Thanks for your update. From the description my understanding is like below:
    > " The page is products-cm.aspx
    > " On the page there's a TreeView like below:
    >
    > <div>
    > <h6><a
    > href="products-cm.aspx?ViewIndex=1">Features</a></h6>
    > <asp:TreeView id="TreeView1" runat="server" NodeIndent="0"
    > NodeWrap="True" Width="217px">
    > <Nodes>
    > <asp:treenode Expanded="True" NavigateUrl="products-cm.aspx?ViewIndex=1"
    > SelectAction="SelectExpand" Text="Basic" Value="Basic">
    > <asp:treenode Text="Messaging" Value="Messaging"
    > NavigateUrl="products-cm.aspx?ViewIndex=5" SelectAction="SelectExpand">
    > </asp:treenode>
    > <asp:treenode Text="Call Routing" Value="CallRouting"
    > NavigateUrl="products-cm.aspx?ViewIndex=6">
    > </asp:treenode>
    > <asp:treenode Text="IVR/Audiotex" Value="IVRAudiotex"
    > NavigateUrl="products-cm.aspx?ViewIndex=7">
    > </asp:treenode>
    > </asp:treenode>
    > <asp:treenode Expanded="True" NavigateUrl="products-cm.aspx?ViewIndex=1"
    > SelectAction="SelectExpand" Text="Advanced" Value="Advanced">
    > <asp:treenode Text="CALLBasic Scripting" Value="CALLBasic"
    > NavigateUrl="products-cm.aspx?ViewIndex=10">
    > </asp:treenode>
    > <asp:treenode Text="Speech Recognition (ASR)" Value="ASR"
    > NavigateUrl="products-cm.aspx?ViewIndex=11">
    > </asp:treenode>
    > <asp:treenode Text="Text-to-Speech (TTS)" Value="TTS"
    > NavigateUrl="products-cm.aspx?ViewIndex=12">
    > </asp:treenode>
    > </asp:treenode>
    > </Nodes>
    > <NodeStyle />
    > <LeafNodeStyle Font-Size="10px" ForeColor="#333333"
    > ImageUrl="customimages/Arrow-Blck.gif" />
    > </asp:TreeView>
    >
    > </div>
    >
    > The expected behavior is:
    >
    > " Initially all nodes of the TreeView are collapsed.
    >
    > " After clicking any "+" icon to expand node and then click the child node
    > to navigate to the same page (with querystring ViewIndex), the expanded
    > node must maintain it's state. Namely if it's expanded before navigation it
    > must still be expanded after navigation.
    >
    > Is my understanding right? If it is, I think you can use following code:
    >
    > <div>
    > <h6><a href="products-cm.aspx?ViewIndex=1">Features</a></h6>
    > <asp:TreeView id="TreeView1" runat="server" NodeIndent="0"
    > NodeWrap="True"
    > Width="217px" >
    > <Nodes>
    > <asp:treenode Expanded="True"
    > NavigateUrl="javascript:__doPostBack('ViewIndex','1')"
    > SelectAction="SelectExpand" Text="Basic" Value="Basic">
    >
    > <asp:treenode Text="Messaging" Value="Messaging"
    > NavigateUrl="javascript:__doPostBack('ViewIndex','5')"
    > SelectAction="SelectExpand">
    > </asp:treenode>
    > <asp:treenode Text="Call Routing" Value="CallRouting"
    > NavigateUrl="javascript:__doPostBack('ViewIndex','6')">
    > </asp:treenode>
    > <asp:treenode Text="IVR/Audiotex" Value="IVRAudiotex"
    > NavigateUrl="javascript:__doPostBack('ViewIndex','7')">
    > </asp:treenode>
    > </asp:treenode>
    > <asp:treenode Expanded="True"
    > NavigateUrl="javascript:__doPostBack('ViewIndex','1')"
    > SelectAction="SelectExpand" Text="Advanced" Value="Advanced">
    > <asp:treenode Text="CALLBasic Scripting" Value="CALLBasic"
    > NavigateUrl="javascript:__doPostBack('ViewIndex','10')">
    > </asp:treenode>
    > <asp:treenode Text="Speech Recognition (ASR)" Value="ASR"
    > NavigateUrl="javascript:__doPostBack('ViewIndex','11')">
    > </asp:treenode>
    > <asp:treenode Text="Text-to-Speech (TTS)" Value="TTS"
    > NavigateUrl="javascript:__doPostBack('ViewIndex','12')">
    > </asp:treenode>
    > </asp:treenode>
    > </Nodes>
    > <NodeStyle />
    > <LeafNodeStyle Font-Size="10px" ForeColor="#333333"
    > ImageUrl="customimages/Arrow-Blck.gif" />
    > </asp:TreeView>
    >
    > </div>
    >
    >
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > if (!IsPostBack) {
    > TreeView1.CollapseAll();
    > }
    > if (Request.Form["__EVENTTARGET"] == "ViewIndex") {
    >
    > if (!String.IsNullOrEmpty(Request.Form["__EVENTARGUMENT"]))
    > {
    > //test
    > Response.Write(Request.Form["__EVENTARGUMENT"]);
    >
    > }
    > }
    > }
    >
    > Your original code in aspx uses URL directly. This will cause a get request
    > sent to server after the child node is clicked. In this case it's difficult
    > to maintain the state of the control. If you have to use get request you
    > probably can store the state in session, which is not a good practise to
    > store state of control because it consumes server side memory and may
    > expire.
    >
    > In my above code a post request will be sent to server after you clicking
    > the child node. In this case we can benefite from internal mechanism of
    > TreeView to maintain the control state during postbacks. As a result of
    > this routine we have to use Request.Form["__EVENTTARGET"] to figure out the
    > selected "ViewIndex", as shown in my code.
    >
    > Regards,
    > Allen Chen
    > Microsoft Online Support
    >
    > Delighting our customers is our #1 priority. We welcome your comments and
    > suggestions about how we can improve the support we provide to you. Please
    > feel free to let my manager know what you think of the level of service
    > provided. You can send feedback directly to my manager at:
    > .
    >
    > ==================================================
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
    >
    > Note: MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 2 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions. Issues of this
    > nature are best handled working with a dedicated Microsoft Support Engineer
    > by contacting Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
    > ==================================================
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    >
    >
    >
    Morris Neuman, Jun 26, 2009
    #6
    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. =?Utf-8?B?VHltYm93?=
    Replies:
    2
    Views:
    24,389
    =?Utf-8?B?VHltYm93?=
    Jan 10, 2006
  2. abargaddon
    Replies:
    0
    Views:
    1,025
    abargaddon
    Jan 17, 2008
  3. Per Salmi

    TreeView not rendering nodes? Cacheing of a TreeView

    Per Salmi, Oct 15, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    429
    Steve Drake
    Oct 15, 2003
  4. Ionutz
    Replies:
    2
    Views:
    509
    Ionutz
    Oct 23, 2005
  5. stepkurt

    Microsoft Treeview vs System Treeview

    stepkurt, Aug 29, 2007, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    351
    Teemu Keiski
    Sep 2, 2007
Loading...

Share This Page