|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Solution - Treeview Site Navigation without ShowExpandCollapseJust 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 Hi.
So does this open the url on the node as well as expand/collapse the node when you click on it? Do you have this working somewhere so I can see it in action? Thanks, Sandhya. theintrepid***@hotmail.com wrote: Show quoteHide quote > 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 Hi Sandhya
Yes, it does. You may view a sample on http://www.freedom2drive.net although this sitemap does not contaion any childnodes it works with childnodes to any level. The only thing it doesn't do is if you have roles and security trimming enabled. I'm working actually right now on a VB.NET update that will store the sitemap in SQL server and allows you to use it in conjunction with roles and security trimming. Contact me on mar***@invent2b.com in case you have any questions. All the best, Martin Invent2b Group sandhy***@gmail.com wrote: Show quoteHide quote > Hi. > > So does this open the url on the node as well as expand/collapse the > node when you click on it? > Do you have this working somewhere so I can see it in action? > > Thanks, > Sandhya. > > theintrepid***@hotmail.com wrote: > > > 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
HyperLinkField and OnRowDataBound
ControlCollection.Remove bug Radiobuttonlist (a custom control) selectedindexchanged event not firing in User Control How do I get a bitmap from the theme? visibly disable img link operations on string Visual Development of Web Controls for SharePoint how to show dialogbox when click on datagrid template column? Data Grid Printing Getting data from templete TextBox |
|||||||||||||||||||||||