Hello,
I have strange problem and hope somebody can give an advice. So I populate my treeview OnTreeNodePopulate="Node_Populate" and i put on the every node over 1-st level a NavigateURL .. But when I run it I can only click on the Root and first Child node and on the other I have no possibility to click. So what can I do to repair this? Any advice is welcome:)
Here is the codebehind:
Code:
Private Sub Node_Populate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs)
If e.Node.ChildNodes.Count = 0 Then
Select Case e.Node.Depth
Case 0
FillFirstLvl(e.Node)
Exit Sub
Case 1
FillSecondLevel(e.Node)
Exit Sub
Case 2
LastFill(e.Node)
Exit Sub
End Select
End If
End Sub
Private Sub FillFirstLvl(ByVal node As TreeNode)
Dim connString As String = ConfigurationManager.ConnectionStrings("autodib").ConnectionString
Dim connection As New OleDb.OleDbConnection(connString)
Dim command As New OleDb.OleDbCommand("SELECT * from MarkaNaKola", connection)
Dim adapter As New OleDb.OleDbDataAdapter(command)
Dim Views As New DataSet()
adapter.Fill(Views)
If Views.Tables.Count > 0 Then
Dim row As DataRow
For Each row In Views.Tables(0).Rows
Dim NewNode As TreeNode = New TreeNode(row("markakola").ToString())
NewNode.PopulateOnDemand = True
NewNode.SelectAction = TreeNodeSelectAction.Expand
node.ChildNodes.Add(NewNode)
Next
End If
End Sub
Public Sub FillSecondLevel(ByVal node As TreeNode)
Dim MarkaKola As String = node.Value
Dim connString As String = ConfigurationManager.ConnectionStrings("autodib").ConnectionString
Dim a As String = "SELECT MarkaNaKola.markakola, Kategoria.CatName FROM MarkaNaKola" & " INNER JOIN Kategoria ON MarkaNaKola.markakola = Kategoria.markakola" & " WHERE MarkaNaKola.markakola = '" & MarkaKola & " '" & " ORDER BY Kategoria.CatName"
Dim connection As New OleDb.OleDbConnection(connString)
Dim command As New OleDb.OleDbCommand(a, connection)
Dim adapter As New OleDb.OleDbDataAdapter(command)
Dim titlesForViews As New DataSet()
adapter.Fill(titlesForViews)
If titlesForViews.Tables.Count > 0 Then
Dim row As DataRow
For Each row In titlesForViews.Tables(0).Rows
Dim NewNode As TreeNode
'NewNode = New TreeNode(row("CatName").ToString(), row("CategorID").ToString())
NewNode = New TreeNode(row("CatName").ToString())
NewNode.PopulateOnDemand = True
NewNode.SelectAction = TreeNodeSelectAction.None
node.NavigateUrl = String.Format("~/VtoroNivo.aspx?markakola=""{0}""", MarkaKola)
node.ChildNodes.Add(NewNode)
Next
End If
End Sub
Private Sub LastFill(ByVal node As TreeNode)
Dim MarkaNaKola As String = node.Parent.Value
Dim Kategoria As String = node.Value
Dim connString As String = ConfigurationManager.ConnectionStrings("autodib").ConnectionString
Dim LastFillCmd As String = "SELECT MarkaNaKola.markakola, Kategoria.CatName, Produkti.ImeProd FROM ((MarkaNaKola INNER JOIN Kategoria ON MarkaNaKola.markakola = Kategoria.markakola) INNER JOIN Produkti ON Kategoria.CategorID = Produkti.CategorID) WHERE (MarkaNaKola.markakola ='" & MarkaNaKola & "'AND (Kategoria.CatName = '" & Kategoria & "'))" & "ORDER BY Kategoria.CatName, Produkti.ImeProd"
Dim connection As New OleDb.OleDbConnection(connString)
Dim command As New OleDb.OleDbCommand(LastFillCmd, connection)
Dim adapter As New OleDb.OleDbDataAdapter(command)
Dim LastFill As New DataSet()
adapter.Fill(LastFill)
If LastFill.Tables.Count > 0 Then
Dim row As DataRow
For Each row In LastFill.Tables(0).Rows
Dim NewNode As TreeNode
NewNode = New TreeNode(row("ImeProd").ToString())
NewNode.PopulateOnDemand = True
NewNode.SelectAction = TreeNodeSelectAction.None
node.NavigateUrl = String.Format("~/VtoroNivo.aspx?markakola=""{0}""", MarkaNaKola)
node.ChildNodes.Add(NewNode)
Next
End If
End Sub
And here is the Html part:
Code:
<asp:TreeView ID="Treeviewz" Runat="Server" ExpandImageUrl="TreeLineImages/minus.gif"
CollapseImageUrl="TreeLineImages/plus.gif"
OnTreeNodePopulate="Node_Populate">
<Nodes>
<asp:TreeNode SelectAction=SelectExpand Text="auto dib" PopulateOnDemand=true/>
</Nodes>
</asp:TreeView>
Thank You,
G. Kalchev