<siteMapNode
url ="contacts/add.aspx"
title ="Add"
description ="Add Contact"
id="AddContacts"/>
<siteMapNode
url ="contacts/print.aspx"
title ="Print"
description ="Print Contacts"
id="PrintContacts"/>
<siteMapNode
url ="contacts/import.aspx"
title ="Import"
description ="Import Contacts"
id="ImportContacts"/>
<siteMapNode
url ="contacts/export.aspx"
title ="Export"
description ="Export Contacts"
id="ExportContacts"/>
</siteMapNode>
<siteMapNode
url="links/list.aspx"
title ="Links"
description ="List Links"
id="Links">
<siteMapNode
url ="links/manage.aspx"
title ="Manage"
description ="Manage Links"
id="ManageLinks"/>
</siteMapNode>
<siteMapNode
url ="files/list.aspx"
title ="Files"
description ="List Files"
id="Files">
<siteMapNode
url ="files/manage.aspx"
title ="Manage"
description ="Manage Files"
id="ManageFiles"/>
</siteMapNode>
</siteMapNode>
The treeView id="secNavMenu"
Basically I have 2 issues. The second issue isn't too bad as I can live with it it. However if I can't figure out the first issue I'm gonna have to manually create <nodes><asp:treeviewnode>.... on each page.
Issue#1 - using the sitemap above I'd like to dynamically collapse all nodes but the selected node. ie. if I'm on the calendar page I'd like all other nodes to be collapsed. I'd like to do this via the .aspx.vb pages for each page
that I have. Otherwise I'll have to manually create the treeViews for each page!
Issue#2 - I can't seem to get it so that "Home" isn't the only Root node. The only way I could work it out so there are no was with all other nodes being children of Home.
Obviously I'm very new to asp.net and I would greatly appreciate any help!
Thanks,
Michael
If everything happens for a reason what is the reason for this error?
Protected Sub TreeView1_TreeNodeExpanded(ByVal sender As Object, ByVal e As TreeNodeEventArgs)
If e.Node.Parent Is Nothing Then
Return
End If
Dim tn As TreeNode = e.Node.Parent
For Each node As TreeNode In tn.ChildNodes
If Not (node = e.Node) Then
node.Collapse
End If
Next
End Sub
overriding the expanded event as shown above should resolve your first issue.
Regarding the second issue, I guess with the sitemap datasource, it is not doable. might be possible with other datasources.
The above would not work if more than one root so improved a little.
Protected Sub TreeView1_TreeNodeExpanded(ByVal sender As Object, ByVal e As TreeNodeEventArgs)
If e.Node.Parent Is Nothing Then
For Each node As TreeNode In (CType(ConversionHelpers.AsWorkaround(sender, GetType(TreeView)), TreeView)).Nodes
If Not (node = e.Node) Then
node.Collapse
End If
Next
Return
End If
Dim tn As TreeNode = e.Node.Parent
For Each node As TreeNode In tn.ChildNodes
If Not (node = e.Node) Then
node.Collapse
End If
Next
End Sub
(1) It says that ConversionHelpers is not declared. (2) (node=e.node) says "=" is not defined for types 'system.web.ui.webcontrols.treenode.
Also, What is it exactly that you are doing in the code above? See my questions underlined next to the code.
Protected Sub TreeView1_TreeNodeExpanded(ByVal sender As Object, ByVal e As TreeNodeEventArgs)
If e.Node.Parent Is Nothing Then If there is no parent node than you'll collapse that node?
For Each node As TreeNode In (CType(ConversionHelpers.AsWorkaround(sender, GetType(TreeView)), TreeView)).Nodes
If Not (node = e.Node) Then I'm not sure what this For statement does. What is the ctype(conversionhelpers.....?
node.Collapse what are you looking for in [not(node=e.node)]?
End If
Next
Return
End If
Dim tn As TreeNode = e.Node.Parent
For Each node As TreeNode In tn.ChildNodes
If Not (node = e.Node) Then
node.Collapse
End If
Next
End Sub
Thanks for the help!
Michael
If everything happens for a reason what is the reason for this error?
Oh, one more thing. I'm not sure that it is possible using the TreeView but I would like to use the root nodes as primary navigation at the top of the screen and the childNodes as the secondary navigation on the left side of the screen. When you click
on the primary nav node I'd like it to only expand or display the secondary navigation of that node.
Michael
If everything happens for a reason what is the reason for this error?
sorry about that I had used the conversion (C# to VB) tool from here http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx
Just replace the older one with
Protected Sub TreeView1_TreeNodeExpanded(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodeExpanded
If e.Node.Parent Is Nothing Then
For Each node As TreeNode In (CType(sender, TreeView)).Nodes
If Not (node.Equals(e.Node)) Then
node.Collapse()
End If
Next
Return
End If
Dim tn As TreeNode = e.Node.Parent
For Each node As TreeNode In tn.ChildNodes
If Not (node.Equals(e.Node)) Then
node.Collapse()
End If
Next
If (e.Node.Depth = 1) Then
End If
End Sub
Regarding the new layout. Can you explain a little more of what you are trying to do?
I have all primary navigation at the top (Home, Calendar, Contacts, Links, Files)
I'd like to have all sub navigation on the left. When you click "Home" the entire treeview should display to the left. However, when you click on "Calendar" only the subnavigation for Calendar should display on the left. It should be like this for Contacts,
Links, Files.... Home is the only primary nav that will list more than just it's own sub navigation.
I can easily do this by manually creating the <asp:treeview> but I would like to figure out a better way to do it using the sitemap. I would also like to use a master page but I am having some difficulty getting the pages to display correctly but I'll figure
that out later.
Michael
If everything happens for a reason what is the reason for this error?
For this purpose you can use the menu control instead with horizontal alignment. In fact I am currently using it in the present project. I am not sure we can do it with TreeView (at least the name sounds like tree).
I am using the menu control with horizontal orientation for the primary (top) navigation. However, I didn't see how using the menu control would do what I was looking for in regards to the secondary (left side) navigation.
If everything happens for a reason what is the reason for this error?
mpaterson
Contributor
4619 Points
1316 Posts
TreeView Collapse and Expand Dynamically
Nov 27, 2006 02:34 AM|LINK
I have been trying for about 3 hours now to figure out how to dynamically expand and collapse treeView nodes.
The treeView is databinded to a siteMap which looks like this:
<siteMapNode url ="default.aspx" title ="Home" description ="Home" id="Home">
<siteMapNode url="calendar/view.aspx" title="Calendar" description="View Calendar" id="Calendar">
<siteMapNode url="events/list.aspx" title="Events" description="List Events" id="Events">
<siteMapNode url ="events/manage.aspx" title ="Manage" description ="Manage Events" id="ManageEvents"/>
</siteMapNode>
<siteMapNode url ="reminders/list.aspx" title ="Reminders" description ="List Reminders" id="Reminders">
<siteMapNode url ="reminders/manage.aspx" title ="Manage" description ="Manage Reminders" id="ManageReminders"/>
</siteMapNode>
</siteMapNode>
<siteMapNode url="contacts/list.aspx" title="Contacts" description="List Contacts" id="Contacts">
<siteMapNode url ="contacts/add.aspx" title ="Add" description ="Add Contact" id="AddContacts"/>
<siteMapNode url ="contacts/print.aspx" title ="Print" description ="Print Contacts" id="PrintContacts"/>
<siteMapNode url ="contacts/import.aspx" title ="Import" description ="Import Contacts" id="ImportContacts"/>
<siteMapNode url ="contacts/export.aspx" title ="Export" description ="Export Contacts" id="ExportContacts"/>
</siteMapNode>
<siteMapNode url="links/list.aspx" title ="Links" description ="List Links" id="Links">
<siteMapNode url ="links/manage.aspx" title ="Manage" description ="Manage Links" id="ManageLinks"/>
</siteMapNode>
<siteMapNode url ="files/list.aspx" title ="Files" description ="List Files" id="Files">
<siteMapNode url ="files/manage.aspx" title ="Manage" description ="Manage Files" id="ManageFiles"/>
</siteMapNode>
</siteMapNode>
The treeView id="secNavMenu"
Basically I have 2 issues. The second issue isn't too bad as I can live with it it. However if I can't figure out the first issue I'm gonna have to manually create <nodes><asp:treeviewnode>.... on each page.
Issue#1 - using the sitemap above I'd like to dynamically collapse all nodes but the selected node. ie. if I'm on the calendar page I'd like all other nodes to be collapsed. I'd like to do this via the .aspx.vb pages for each page that I have. Otherwise I'll have to manually create the treeViews for each page!
Issue#2 - I can't seem to get it so that "Home" isn't the only Root node. The only way I could work it out so there are no was with all other nodes being children of Home.
Obviously I'm very new to asp.net and I would greatly appreciate any help!
Thanks,
Michael
ubaid1900
Participant
918 Points
187 Posts
Re: TreeView Collapse and Expand Dynamically
Nov 27, 2006 10:16 PM|LINK
Protected Sub TreeView1_TreeNodeExpanded(ByVal sender As Object, ByVal e As TreeNodeEventArgs)
If e.Node.Parent Is Nothing Then
Return
End If
Dim tn As TreeNode = e.Node.Parent
For Each node As TreeNode In tn.ChildNodes
If Not (node = e.Node) Then
node.Collapse
End If
Next
End Sub
overriding the expanded event as shown above should resolve your first issue.
Regarding the second issue, I guess with the sitemap datasource, it is not doable. might be possible with other datasources.
Hope it helped. Thanks
ubaid1900
Participant
918 Points
187 Posts
Re: TreeView Collapse and Expand Dynamically
Nov 27, 2006 10:27 PM|LINK
The above would not work if more than one root so improved a little.
Protected Sub TreeView1_TreeNodeExpanded(ByVal sender As Object, ByVal e As TreeNodeEventArgs)
If e.Node.Parent Is Nothing Then
For Each node As TreeNode In (CType(ConversionHelpers.AsWorkaround(sender, GetType(TreeView)), TreeView)).Nodes
If Not (node = e.Node) Then
node.Collapse
End If
Next
Return
End If
Dim tn As TreeNode = e.Node.Parent
For Each node As TreeNode In tn.ChildNodes
If Not (node = e.Node) Then
node.Collapse
End If
Next
End Sub
Hope it helped. Thanks
mpaterson
Contributor
4619 Points
1316 Posts
Re: TreeView Collapse and Expand Dynamically
Nov 27, 2006 11:42 PM|LINK
A few things:
(1) It says that ConversionHelpers is not declared. (2) (node=e.node) says "=" is not defined for types 'system.web.ui.webcontrols.treenode.
Also, What is it exactly that you are doing in the code above? See my questions underlined next to the code.
Protected Sub TreeView1_TreeNodeExpanded(ByVal sender As Object, ByVal e As TreeNodeEventArgs)
If e.Node.Parent Is Nothing Then If there is no parent node than you'll collapse that node?
For Each node As TreeNode In (CType(ConversionHelpers.AsWorkaround(sender, GetType(TreeView)), TreeView)).Nodes
If Not (node = e.Node) Then I'm not sure what this For statement does. What is the ctype(conversionhelpers.....?
node.Collapse what are you looking for in [not(node=e.node)]?
End If
Next
Return
End If
Dim tn As TreeNode = e.Node.Parent
For Each node As TreeNode In tn.ChildNodes
If Not (node = e.Node) Then
node.Collapse
End If
Next
End Sub
Thanks for the help!
Michael
mpaterson
Contributor
4619 Points
1316 Posts
Re: TreeView Collapse and Expand Dynamically
Nov 27, 2006 11:45 PM|LINK
Oh, one more thing. I'm not sure that it is possible using the TreeView but I would like to use the root nodes as primary navigation at the top of the screen and the childNodes as the secondary navigation on the left side of the screen. When you click on the primary nav node I'd like it to only expand or display the secondary navigation of that node.
Michael
ubaid1900
Participant
918 Points
187 Posts
Re: TreeView Collapse and Expand Dynamically
Nov 28, 2006 01:22 AM|LINK
sorry about that I had used the conversion (C# to VB) tool from here http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx
Just replace the older one with
Protected Sub TreeView1_TreeNodeExpanded(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodeExpanded
If e.Node.Parent Is Nothing Then
For Each node As TreeNode In (CType(sender, TreeView)).Nodes
If Not (node.Equals(e.Node)) Then
node.Collapse()
End If
Next
Return
End If
Dim tn As TreeNode = e.Node.Parent
For Each node As TreeNode In tn.ChildNodes
If Not (node.Equals(e.Node)) Then
node.Collapse()
End If
Next
If (e.Node.Depth = 1) Then
End If
End Sub
Regarding the new layout. Can you explain a little more of what you are trying to do?
Thanks
ubaid1900
Participant
918 Points
187 Posts
Re: TreeView Collapse and Expand Dynamically
Nov 28, 2006 01:39 AM|LINK
remove these lines
If (e.Node.Depth = 1) Then
End If
mpaterson
Contributor
4619 Points
1316 Posts
Re: TreeView Collapse and Expand Dynamically
Nov 28, 2006 03:36 PM|LINK
Thanks a lot. I'll try this out when I get home.
Regarding what I'm trying to do:
I have all primary navigation at the top (Home, Calendar, Contacts, Links, Files)
I'd like to have all sub navigation on the left. When you click "Home" the entire treeview should display to the left. However, when you click on "Calendar" only the subnavigation for Calendar should display on the left. It should be like this for Contacts, Links, Files.... Home is the only primary nav that will list more than just it's own sub navigation.
I can easily do this by manually creating the <asp:treeview> but I would like to figure out a better way to do it using the sitemap. I would also like to use a master page but I am having some difficulty getting the pages to display correctly but I'll figure that out later.
Michael
ubaid1900
Participant
918 Points
187 Posts
Re: TreeView Collapse and Expand Dynamically
Nov 28, 2006 03:50 PM|LINK
For this purpose you can use the menu control instead with horizontal alignment. In fact I am currently using it in the present project. I am not sure we can do it with TreeView (at least the name sounds like tree).
Thanks.
mpaterson
Contributor
4619 Points
1316 Posts
Re: TreeView Collapse and Expand Dynamically
Nov 28, 2006 06:56 PM|LINK