ASP 2.0 Menu Control Fed From Database

R

Rob

I want to feed the menu control from a database which is set up as
WebPageID, WebPageParent, URL where the WebPage Id is the primary key
and the WebpageParent is the foreign key. The menu will have multiple
nodes.

This example works in the treeview but I would really like to use the
horizontal orientation of the menu control. I understand that I may
lose the populate on command.

Does anyone know how to populate the menu control with multiple nodes
from a database?

Thank you in advance for the help.

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">

Const connectionString As String = "Server=MySQLServer;
UID=MySQLUserID; Password=MyPassword"

Sub TreeView1_TreeNodePopulate(sender As Object, e As
TreeNodeEventArgs)
Dim con As new SqlConnection(connectionString)
Dim cmd As New SqlCommand("SELECT [WebPageID],
[WebPageDescription], [WebPageURL], [WebPageParent] " & _
"FROM [MyDatabase].[dbo].[D_MyWebPages] " & _
"WHERE WebPageParent=@WebPageParent", con)
cmd.Parameters.AddWithValue("@WebPageParent", e.Node.Value)
con.Open()
Try
Dim dtr As SqlDataReader = cmd.ExecuteReader()
While dtr.Read()
Dim newNode As new TreeNode()
newNode.PopulateOnDemand = True
newNode.Text = dtr("WebPageDescription").ToString()
newNode.Value = dtr("WebPageID").ToString()
e.Node.ChildNodes.Add(newNode)
End While
Finally
con.Close()
End Try
End Sub

</script>

<html>
<head runat="Server">
<title>Dynamic TreeView</title>
</head>
<body>
<form id="form1" runat="server">
<asp:TreeView
id="TreeView1"
ImageSet="Arrows"
ShowLines="true"
ExpandDepth="1"
OnTreeNodePopulate="TreeView1_TreeNodePopulate"
Runat="Server">
<Nodes>
<asp:TreeNode
Text="Messages"
Value="1"
PopulateOnDemand="true" />
</Nodes>
</asp:TreeView>
<ASP:Table
Runat="Server"
GridLines="Horizontal"
CellPadding="0"
CellSpacing="0"
Width="100%"
CssClass="Headings"<asp:TableRow Runat="Server" CssClass="Title">
<ASP:TableCell runat="Server" HorizontalAlign="Left"
VerticalAlign="Top">

</ASP:TableCell>
<ASP:TableCell runat="Server" HorizontalAlign="Left"
VerticalAlign="Top">
Here is some Text that would sit in the left most column
</ASP:TableCell>
</asp:TableRow>
<asp:TableRow Runat="Server" CssClass="Headings">
<ASP:TableCell runat="Server" ColumnSpan="2">

</ASP:TableCell>
</asp:TableRow>
</asp:Table>
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top