|
When i drag and drop the tree view control to the page,
on the control a message is displaying like: Error parsing control:Object referance not set to an instance of an object
And then what value i can pass to the -populatetree- recursive function
Can U please cut and paste the code
i called bellow function using
Dim oTreeNode As New TreeNode
TreeView1.Nodes.Add(oTreeNode)
PopulateTree(0, TreeView1.Nodes(0))
but tree not displayed..........
Public Sub PopulateTree(ByVal ParentId As String, ByVal TVNode As TreeNode)
Dim oDataView As New DataView(odataset.Tables(0), "CATEGORYPARENT='" & ParentId & "'", "CATEGORYNAME", DataViewRowState.OriginalRows)
Dim oDataRow As DataRowView
For Each oDataRow In oDataView
Dim oTreeNode As New TreeNode(oDataRow("CATEGORYNAME"))
'Dim oComboBox As New ComboBox
If TVNode Is Nothing Then
Else
TreeView1.ChildNodes.Add(oTreeNode)
' For Winform TreeView1.Nodes.Add(oTreeNode)
PopulateTree(oDataRow("CATEGORYCODE"), oTreeNode)
End If
Next
End Sub
Try Changing Line TreeView1.Nodes.Add(oTreeNode) in PopulateTree to
TVNode.Nodes.Add(oTreeNode)
' For ASP .NET Use TVNode.Nodes.ChildNodes.Add(oTreeNode)
I guess thats the problem.
Any Way here's the correct working code for asp.net
Public Sub PopulateTree(ByVal ParentId As String, ByVal TVNode As TreeNode, ByVal odataset As DataSet)
Dim oDataView As New DataView(odataset.Tables(0), "CATEGORYPARENT='" & ParentId & "'", "CATEGORYNAME", DataViewRowState.OriginalRows)
Dim oDataRow As DataRowView
For Each oDataRow In oDataView
Dim oTreeNode As New TreeNode(oDataRow("CATEGORYNAME"))
'Dim oComboBox As New ComboBox
If TVNode Is Nothing Then
Else
TVNode.ChildNodes.Add(oTreeNode)
PopulateTree(oDataRow("CATEGORYCODE"), oTreeNode, odataset)
End If
Next
End Sub
|