Hi,
For some reason my code is not working.....It shows the Root level, but nothing else.
Below is my code, please could someone helpme ? Thanks for any help :)
'Root Level - Step 3
Private Sub PopulateRootLevel()
Dim objConn As String = ConfigurationManager.AppSettings("Fleetcube.ConnectionString")Dim myConnection As New System.Data.SqlClient.SqlConnection(objConn)
Dim objCommand As New SqlCommand("select id,name,parentBranchID, org_Organization_id, (select count(*) FROM org_Branch " _& "WHERE org_Organization_id = " & Session.Item("Admin_id") & ") childnodecount FROM org_Branch where parentBranchID = 0 AND org_organization_id =" & Session.Item("Admin_id"), _
myConnection)
Dim da As New SqlDataAdapter(objCommand)Dim dt As New DataTable()
da.Fill(dt)
PopulateNodes(dt, TreeView1.Nodes)
End Sub
'Nodes - Step 3Private Sub PopulateNodes(ByVal dt As DataTable, _
ByVal nodes As TreeNodeCollection)For Each dr As DataRow In dt.Rows
Dim tn As New TreeNode()tn.Text = dr("name").ToString()tn.Value = dr("id").ToString()
nodes.Add(tn)
'If node has child nodes, then enable on-demand populatingtn.PopulateOnDemand = (CInt(dr("childnodecount")) > 0)
Next
End Sub
'Sub levels - Step 3Private Sub PopulateSubLevel(ByVal parentid As Integer, ByVal parentNode As TreeNode)
Dim objConn As String = ConfigurationManager.AppSettings("Fleetcube.ConnectionString")Dim myConnection As New System.Data.SqlClient.SqlConnection(objConn)
Dim objCommand As New SqlCommand("select id,name,org_Organization_id,(select count(*) FROM org_Branch " _& "WHERE org_Organization_id = " & Session.Item("Admin_id") & ") childnodecount FROM org_Branch where parentBranchID=@parentBranchID", _
myConnection)
objCommand.Parameters.Add("@parentBranchID", SqlDbType.Int).Value = parentid
Dim da As New SqlDataAdapter(objCommand)Dim dt As New DataTable()
da.Fill(dt)
PopulateNodes(dt, parentNode.ChildNodes)
End SubProtected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
PopulateRootLevel()
End If
End Sub
<form id="form1" runat="server">
<div><asp:TreeView ID="TreeView1" runat="server"
ExpandDepth="0"
HoverNodeStyle-ForeColor="red"OnSelectedNodeChanged="TreeView1_SelectedNodeChanged"
PopulateNodesFromClient="true"
ShowExpandCollapse="true"PopulateOnDemand="true"
ShowLines="True">
</asp:TreeView>
</div>
</form>