kjohnson530
IS-IT--Management
I am new to working with ASPX and would only consider myself to be moderately skilled with ASP. I am currently trying to learn to work with ASP.NET using Visual Web Developer 2005. My question is about building a dynamic tree menu. I have found documentation from Microsoft on how to build the menu (though from what I understand it isn't the optimal way to do it). And though I have the menu the way I would like to see it, I don't know how to link the menu items to produce the effect I would like.
What I'm trying to accomplish is to build a menu on the left, and open specific (selected)data into a new page using a frame on the right.
below is my code. Any help that you all can provide would be greatly appreciated.
Thanks in advance for helping a novice out.
What I'm trying to accomplish is to build a menu on the left, and open specific (selected)data into a new page using a frame on the right.
below is my code. Any help that you all can provide would be greatly appreciated.
Code:
<%@ Page Language="VB" %>
<%@ Import Namespace="System.data" %>
<%@ import Namespace="System.Data.Sqlclient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<script runat="server">
Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) _
Handles TreeView1.TreeNodePopulate
If e.Node.ChildNodes.Count = 0 Then
Select Case e.Node.Depth
Case 0
PopulateCategories(e.Node)
Case 1
PopulateProducts(e.Node)
End Select
End If
End Sub
Sub PopulateCategories(ByVal node As TreeNode)
Dim Varcat1 As Integer = 0
Dim sqlQuery As New SqlCommand( _
"Select Status,StatusID From tblstatus")
Dim ResultSet As DataSet
ResultSet = RunQuery(sqlQuery)
If ResultSet.Tables.Count > 0 Then
Dim row As DataRow
For Each row In ResultSet.Tables(0).Rows
Dim NewNode As TreeNode = New _
TreeNode(row("Status").ToString(), _
row("StatusID").ToString())
NewNode.PopulateOnDemand = True
NewNode.SelectAction = TreeNodeSelectAction.Expand
node.ChildNodes.Add(NewNode)
Next
End If
End Sub
Sub PopulateProducts(ByVal node As TreeNode)
Dim sqlQuery As New SqlCommand
sqlQuery.CommandText = "Select WOID From tblWO " & _
" Where StatusID = @StatusID "
sqlQuery.Parameters.Add("Statusid", SqlDbType.Int).Value = _
node.Value
Dim ResultSet As DataSet = RunQuery(sqlQuery)
If ResultSet.Tables.Count > 0 Then
Dim row As DataRow
For Each row In ResultSet.Tables(0).Rows
Dim NewNode As TreeNode = New _
TreeNode(row("WOId").ToString())
NewNode.PopulateOnDemand = False
NewNode.SelectAction = TreeNodeSelectAction.None
node.ChildNodes.Add(NewNode)
Next
End If
End Sub
Function RunQuery(ByVal sqlQuery As SqlCommand) As DataSet
Dim connectionString As String
connectionString = _
ConfigurationManager.ConnectionStrings _
("ITConnectionString").ConnectionString
Dim dbConnection As New SqlConnection
dbConnection.ConnectionString = connectionString
Dim dbAdapter As New SqlDataAdapter
dbAdapter.SelectCommand = sqlQuery
sqlQuery.Connection = dbConnection
Dim resultsDataSet As DataSet = New DataSet
Try
dbAdapter.Fill(resultsDataSet)
Catch ex As Exception
labelStatus.Text = "Unable to connect to SQL Server."
End Try
Return resultsDataSet
End Function
</script>
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TreeView ID="TreeView1" runat="server" MaxDataBindDepth="2" OnTreeNodePopulate="TreeView1_TreeNodePopulate"
Style="z-index: 100; left: 20px; position: absolute; top: 94px" ExpandDepth="1" Height="28px" Width="74px">
<Nodes>
<asp:TreeNode PopulateOnDemand="True" Text="Status" Value="Product List" NavigateUrl="~/WO/WOReview.aspx" Target="Main"></asp:TreeNode>
</Nodes>
</asp:TreeView>
<asp:Label ID="LabelStatus" runat="server" Style="z-index: 102; left: 12px; position: absolute;
top: 66px" Text="Label" Width="131px" Visible="False"></asp:Label>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ITConnectionString %>"
SelectCommand="SELECT * FROM [tblWO]"></asp:SqlDataSource>
</form>
</body>
</html>
Thanks in advance for helping a novice out.