<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:TreeView ID="TreeView1" runat="server" ImageSet="Arrows" ShowLines="True" OnTreeNodePopulate="PopulateNode" EnableClientScript="true" PopulateNodesFromClient="true"> <Nodes><asp:TreeNode Text="Tree View" SelectAction="SelectExpand" PopulateOnDemand="true" NavigateUrl="~/admin/ontuse.aspx" ToolTip="Treeview for O N T's"/></Nodes> <ParentNodeStyle Font-Bold="False" /> <SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD" HorizontalPadding="0px" VerticalPadding="0px" /> <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" /> <HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" /> </asp:TreeView> <asp:Label id="Message" runat="server"/> </div> </form> </body> </html>
Imports System.Data Imports System.Data.SqlClient Partial Class admin_test Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Sub PopulateNode(ByVal sender As Object, ByVal e As TreeNodeEventArgs) Select Case e.Node.Depth Case 0 area(e.Node) Case 1 block(e.Node) Case 2 ontinstall(e.Node) Case Else End Select End Sub Sub area(ByVal node As TreeNode) Dim ResultSet As DataSet = RunQuery("Select area_id, area_Name From area") If ResultSet.Tables.Count > 0 Then Dim row As DataRow For Each row In ResultSet.Tables(0).Rows Dim newNode As New TreeNode() newNode.Text = "Root" 'row("Area_Name").ToString() newNode.Value = row("area_ID").ToString() newNode.ToolTip = "Area Name" newNode.Target = "_blank" newNode.NavigateUrl = "ontuse.aspx?id=" & newNode.Value newNode.PopulateOnDemand = True newNode.SelectAction = TreeNodeSelectAction.None newNode.CollapseAll() node.ChildNodes.Add(newNode) Next End If End Sub Sub block(ByVal node As TreeNode) Dim ResultSet As DataSet = RunQuery("Select block_id, block_Name From block Where area_ID=" & node.Value) If ResultSet.Tables.Count > 0 Then Dim row As DataRow For Each row In ResultSet.Tables(0).Rows Dim newNode As New TreeNode() newNode.Text = "Parent" 'row("block_Name").ToString() newNode.Value = row("block_ID").ToString() newNode.ToolTip = "Block Name" newNode.PopulateOnDemand = True newNode.SelectAction = TreeNodeSelectAction.None newNode.Target = "_blank" newNode.NavigateUrl = "ontuse.aspx?id=" & newNode.Value node.ChildNodes.Add(newNode) Next End If End Sub Sub ontinstall(ByVal node As TreeNode) Dim ResultSet As DataSet = RunQuery("Select * From ont_install Where block_ID=" & node.Value & " order by ont_name") If ResultSet.Tables.Count > 0 Then Dim row As DataRow For Each row In ResultSet.Tables(0).Rows Dim newNode As New TreeNode() newNode.Text = "Leaf" 'row("ont_name").ToString() newNode.Value = row("ont_id").ToString() newNode.ToolTip = "O N T Name" newNode.Target = "_blank" newNode.NavigateUrl = "ontuse.aspx?id=" & newNode.Value newNode.PopulateOnDemand = True newNode.SelectAction = TreeNodeSelectAction.None node.ChildNodes.Add(newNode) Next End If End Sub Function RunQuery(ByVal QueryString As String) As DataSet Dim ConnectionString As String = "Data Source=den;Initial Catalog=ont;Integrated Security=True" Dim DBConnection As SqlConnection = New SqlConnection(ConnectionString) Dim DBAdapter As SqlDataAdapter Dim ResultsDataSet As DataSet = New DataSet Try DBAdapter = New SqlDataAdapter(QueryString, DBConnection) DBAdapter.Fill(ResultsDataSet) DBConnection.Close() Catch ex As Exception If DBConnection.State = ConnectionState.Open Then DBConnection.Close() End If Message.Text = "Unable to connect to the database." End Try Return ResultsDataSet End Function End Class
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)