I have an asp.net page with a TreeView that is bound to a SiteMapDataSource object.
What I would like to do is each time a user selects an item in the TreeView, automatically collapse all other branches that are not part of the selected item. I have spent the last day searching for possible solutions and am starting from scratch because either (a) it caused an "infinite loop" error or (b) it simply didn't do what I needed it to do.
Any help would be appreciated.
Here is the code showing the relevant objects:
<asp:SiteMapDataSource ID="smdsProdcutsMenu" runat="server" StartingNodeUrl="~/Products/products.aspx" /> <asp:TreeView ID="tvCategory" runat="server" CssClass="Treeview" NodeWrap="true" DataSourceID="smdsProdcutsMenu" ShowLines="True" ontreenodeexpanded="TreeNodeExpanded"> <SelectedNodeStyle BackColor="White" Font-Bold="True" ForeColor="Blue" /> </asp:TreeView>
Through testing, I have seen that the only event triggered by clicking on an item in the Treeview is TreeNodeExpanded.
The scriptblock is empty now because I am starting from square one and do not know what to put here. Here is where I need help.
<script runat="server"> Protected Sub TreeNodeExpanded(sender As Object, e As System.Web.UI.WebControls.TreeNodeEventArgs) ' (1) what item was just clicked? ' (2) Collapse everything not contained in the branch of the selected item. End Sub </script>
Thank you for any help.