Tree View acting up and not expanding nodes :(

Last post 05-09-2008 5:30 AM by AxleWack. 1 replies.

Sort Posts:

  • Tree View acting up and not expanding nodes :(

    05-09-2008, 5:05 AM
    • Loading...
    • AxleWack
    • Joined on 10-02-2007, 8:56 AM
    • Posts 227

    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 3

    Private 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 populating

    tn.PopulateOnDemand = (CInt(dr("childnodecount")) > 0)

    Next

    End Sub

     

    'Sub levels - Step 3

    Private 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 Sub

    Protected 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>

  • Re: Tree View acting up and not expanding nodes :(

    05-09-2008, 5:30 AM
    Answer
    • Loading...
    • AxleWack
    • Joined on 10-02-2007, 8:56 AM
    • Posts 227

    Nevermind

     

    SOrted

     

    Forgot to add this coding

    Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodePopulate

    PopulateSubLevel(CInt(e.Node.Value), e.Node)

    End Sub

Page 1 of 1 (2 items)