I have a tree menu on the page that loads fine on the initial page load along with a dropdownlist that autopostback's with a new usertype. With that usertype I populate the tree again with the appropriate menu(well its suppose to), but it only runs the intial root level and doesn't fill in the rest.
<asp:DropDownList ID="roleDDL" AutoPostBack="true" runat="server">
</asp:DropDownList><br />
<div style="border:solid 0px #ff0000;background:#ffffff;color:#ffffff; width : 100%; height : 350px; overflow : auto; ">
<asp:TreeView ID="TreeView3" ExpandDepth="FullyExpand" ShowCheckBoxes="All" RootNodeStyle-ImageUrl="~/images/computer.gif" ParentNodeStyle-ImageUrl="~/images/folder.gif" PopulateNodesFromClient="true" ShowLines="true" ShowExpandCollapse="false" runat="server">
<NodeStyle Font-Names="Arial" Font-Size="8pt" ForeColor="DarkBlue" HorizontalPadding="5"/>
<RootNodeStyle Font-Bold="True" Font-Size="9pt"/>
<HoverNodeStyle Font-UnderLine="True" />
</asp:TreeView>
If Not Page.IsPostBack Then
Buffer = True
populateRoleDDL()
PopulateRootLevel2()
'Panel1.visible = False
TreeView1.Visible = True
TreeView3.Visible = True
End If
Private Sub PopulateRootLevel2()
Dim dbConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString)
'Dim myCommand As New SqlCommand("prcGetNodesByUserTypeID", dbConnection)
Dim myCommand As New SqlCommand("select id,name,(select count(*) FROM tblNode WHERE parentid=sc.id) childnodecount FROM tblNode sc where parentID IS NULL", dbConnection)
'myCommand.CommandType() = Data.CommandType.StoredProcedure
'myCommand.Parameters.Add("@UserTypeID", SqlDbType.Int).Value = 1
Dim da2 As New SqlDataAdapter(myCommand)
Dim dt2 As New DataTable()
da2.Fill(dt2)
PopulateNodes2(dt2, TreeView3.Nodes)
dbConnection.Close()
myCommand.Dispose()
End Sub
Private Sub PopulateNodes2(ByVal dt2 As DataTable, ByVal nodes2 As TreeNodeCollection)
For Each dr2 As DataRow In dt2.Rows
Dim tn2 As New TreeNode()
tn2.Text = dr2("Name").ToString()
tn2.Value = dr2("ID").ToString()
'tn2.NavigateUrl = "folderfilecleanup.aspx?gip=" & dr2("ID").ToString()
tn2.SelectAction = TreeNodeSelectAction.None
'tn2.Target = "menuSelectB"
'tn.ShowCheckBox = True
'tn.Checked = True
tn2.Target = "_self"
'tn2.SelectAction = TreeNodeSelectAction.Expand
nodes2.Add(tn2)
'If node has child nodes, then enable on-demand populating
tn2.PopulateOnDemand = (CInt(dr2("childnodecount")) > 0)
Next
End Sub
Private Sub PopulateSubLevel2(ByVal parentid2 As Integer, ByVal parentNode2 As TreeNode)
Dim tempUserTypeID As Integer
tempUserTypeID = 1
Dim dbConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString)
'Dim objCommand As New SqlCommand("select id,name,(select count(*) FROM tblNode WHERE parentid=sc.id) childnodecount FROM tblNode sc JOIN where parentID=@parentID and ", dbConnection)
Dim objCommand As New SqlCommand("select sc.id,sc.name,(select count(*) FROM tblNode tan WHERE tan.parentid=sc.id) childnodecount FROM tblNode sc JOIN tblNodeUserType tut ON tut.NodeID = sc.ID WHERE sc.parentID=@parentID and tut.UserTypeID = @UserTypeID and sc.Active=1", dbConnection)
objCommand.Parameters.Add("@parentID", SqlDbType.Int).Value = parentid2
'If roleDDL.SelectedValue = "Choose a Type" Then
' objCommand.Parameters.Add("@UserTypeID", SqlDbType.Int).Value = 0
'Else
' objCommand.Parameters.Add("@UserTypeID", SqlDbType.Int).Value = Session("usertypeid") 'roleDDL.SelectedValue
'End If
objCommand.Parameters.Add("@UserTypeID", SqlDbType.Int).Value = roleDDL.SelectedValue ' Session("usertypeid")
Dim da2 As New SqlDataAdapter(objCommand)
Dim dt2 As New DataTable()
da2.Fill(dt2)
PopulateNodes2(dt2, parentNode2.ChildNodes)
End Sub
Private Sub TreeView3_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView3.TreeNodePopulate
PopulateSubLevel2(CInt(e.Node.Value), e.Node)
End Sub
Protected Sub roleDDL_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles roleDDL.SelectedIndexChanged
TreeView3.Nodes.Clear()
PopulateRootLevel2()
End Sub
- km
______________________________________
"always here and always forever"