hi all,
i read all day articles on this problem and i've tried many different solutions but none really solved my problem.
my situation :
- i have a treeview placed inside a panel, per default, this panel is hidden, when a user clicks on a linkbutton this panel is made visible.
- my treeview is been created from the code behind, because all items are loaded from a sql datasource
- my treeview has irregular nodes, sometimes the root has no child, in other cases it does have childes.
my problem :
- when a user clicks on a childnode, which is a hyperlink, the browser goes to that page and the treeview collapses. now i want that my treeview stay's open at the node where the child is located.
my page :
<asp:Panel runat="server" ID="pWines" Visible="false">
<asp:TreeView CssClass="winesubmenu" ID="tvWines" runat="server" NodeIndent="8" ExpandDepth="0">
</asp:TreeView>
</asp:Panel>
my code:
Protected Sub lbWine_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbWine.Click
If lbWine.CommandName = "Show" Then
pWines.Visible = True
lbWine.CommandName = "Hide"
LoadWineCategories()
ElseIf lbWine.CommandName = "Hide" Then
pWines.Visible = False
lbWine.CommandName = "Show"
End If
End Sub
Private Sub LoadWineCategories()
If Not tvWines.Nodes.Count > 0 Then
Dim tnRoot As New TreeNode
Dim tnChild As New TreeNode
Dim dtCategories, dtSubCategories As DataTable
Dim drCategory, drSubCategory As DataRow
dtCategories = WS.GetWineCategories(Profile.Culture).Tables(0)
For Each drCategory In dtCategories.Rows
tnRoot = New TreeNode
tnRoot.Text = drCategory("Category")
tnRoot.Value = drCategory("CID")
If CType(drCategory("CHasChild"), Boolean) Then
dtSubCategories = WS.GetWineSubCategories(Profile.Culture, drCategory("CID")).Tables(0)
For Each drSubCategory In dtSubCategories.Rows
tnChild = New TreeNode
tnChild.Text = drSubCategory("Category")
tnChild.Value = drSubCategory("CID")
tnChild.NavigateUrl = String.Format("~/products/wines/{0}/{1}.aspx", shared_functions.CleanURL(drCategory("Category")), shared_functions.CleanURL(drSubCategory("Category")))
tnRoot.ChildNodes.Add(tnChild)
Next
Else
tnRoot.NavigateUrl = String.Format("~/products/wines/{0}.aspx", shared_functions.CleanURL(drCategory("Category")))
End If
tvWines.Nodes.Add(tnRoot)
Next
End If
End Sub
Protected
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
CheckOnPostback()
End If
End Sub
Private Sub CheckOnPostback()
If Request.RawUrl.Contains("wines") Then
LoadWineCategories()
pWines.Visible = True
End If
End Sub
Face your fears, Live Your Dreams