T
theintrepidfox
Dear Group
Just thought of posting a solution on how to use an Microsoft ASP.NET
2.0 treeview control for simple site navigation without the need of
using the Expand/Collapse image click option.
Instead Treeview expands (or not) when a treenode text is clicked. Note
that it's probably not foolproof (not tested) but it works for me.
If you have any ideas of improvement, please post the code here or
email me.
Hth and gets you started,
Martin
What you need:
- A Sitemap. Each node must point to a local aspx.
- SiteMapDataSource and a SiteMapProvider
- Treeview on your master page (called mnuSideNav in this example)
- Place the following in your master code beside:
Protected Sub TreeView1_DataBound(ByVal sender As Object, ByVal e
As System.EventArgs) Handles mnuSideNav.DataBound
Dim SitemapNode As SiteMapNode =
SiteMapDataSource1.Provider.CurrentNode
'Build Current SiteMapPath To Root
'- Add Current Node
Dim Path(0) As String
Path.SetValue(SitemapNode.Title.ToString, 0)
'- Work Way Up To Root, Adding ParentNodes
Dim i As Integer = 1
While SitemapNode.ParentNode.Title <> ""
ReDim Preserve Path(i)
Path.SetValue(SitemapNode.ParentNode.Title.ToString, i)
SitemapNode = SitemapNode.ParentNode
i += 1
End While
'- Reverse Array To Reflect Root To CurrentNode
Array.Reverse(Path)
'Find TreeNodes in Array And Expand Tree
Dim TreeNode As TreeNode
Dim ii As Integer = 0
Dim TreePath As String
While ii < Path.Length
TreePath += Path.GetValue(ii) 'Set To First Value in Path
Array Or Ammdend Treepath.
TreeNode = mnuSideNav.FindNode(TreePath)
'Expand Current Node
TreeNode.Expand()
'Ammend Tree ValuePath
TreePath += mnuSideNav.PathSeparator.ToString
ii += 1
End While
End Sub
Just thought of posting a solution on how to use an Microsoft ASP.NET
2.0 treeview control for simple site navigation without the need of
using the Expand/Collapse image click option.
Instead Treeview expands (or not) when a treenode text is clicked. Note
that it's probably not foolproof (not tested) but it works for me.
If you have any ideas of improvement, please post the code here or
email me.
Hth and gets you started,
Martin
What you need:
- A Sitemap. Each node must point to a local aspx.
- SiteMapDataSource and a SiteMapProvider
- Treeview on your master page (called mnuSideNav in this example)
- Place the following in your master code beside:
Protected Sub TreeView1_DataBound(ByVal sender As Object, ByVal e
As System.EventArgs) Handles mnuSideNav.DataBound
Dim SitemapNode As SiteMapNode =
SiteMapDataSource1.Provider.CurrentNode
'Build Current SiteMapPath To Root
'- Add Current Node
Dim Path(0) As String
Path.SetValue(SitemapNode.Title.ToString, 0)
'- Work Way Up To Root, Adding ParentNodes
Dim i As Integer = 1
While SitemapNode.ParentNode.Title <> ""
ReDim Preserve Path(i)
Path.SetValue(SitemapNode.ParentNode.Title.ToString, i)
SitemapNode = SitemapNode.ParentNode
i += 1
End While
'- Reverse Array To Reflect Root To CurrentNode
Array.Reverse(Path)
'Find TreeNodes in Array And Expand Tree
Dim TreeNode As TreeNode
Dim ii As Integer = 0
Dim TreePath As String
While ii < Path.Length
TreePath += Path.GetValue(ii) 'Set To First Value in Path
Array Or Ammdend Treepath.
TreeNode = mnuSideNav.FindNode(TreePath)
'Expand Current Node
TreeNode.Expand()
'Ammend Tree ValuePath
TreePath += mnuSideNav.PathSeparator.ToString
ii += 1
End While
End Sub