TreeView


M

Morris Neuman

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.
 
Ad

Advertisements

A

Allen Chen [MSFT]

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 (e-mail address removed). 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:
(e-mail address removed).

==================================================
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.
 
A

Allen Chen [MSFT]

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

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:
(e-mail address removed).

==================================================
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.
 
Ad

Advertisements

M

Morris Neuman

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 said:
Hi Morris,
FYI, the email is being sent by my colleague Jer Mehta.

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:
(e-mail address removed).

==================================================
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.
 
Ad

Advertisements


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

Top