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="Syst em.Data" %>
<%@ Import Namespace="Syst em.Data.SqlClie nt" %>
<script runat="server">
Const connectionStrin g As String = "Server=MySQLSe rver;
UID=MySQLUserID ; Password=MyPass word"
Sub TreeView1_TreeN odePopulate(sen der As Object, e As
TreeNodeEventAr gs)
Dim con As new SqlConnection(c onnectionString )
Dim cmd As New SqlCommand("SEL ECT [WebPageID],
[WebPageDescript ion], [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.ExecuteRead er()
While dtr.Read()
Dim newNode As new TreeNode()
newNode.Populat eOnDemand = True
newNode.Text = dtr("WebPageDes cription").ToSt ring()
newNode.Value = dtr("WebPageID" ).ToString()
e.Node.ChildNod es.Add(newNode)
End While
Finally
con.Close()
End Try
End Sub
</script>
<html>
<head runat="Server">
<title>Dynami c TreeView</title>
</head>
<body>
<form id="form1" runat="server">
<asp:TreeView
id="TreeView1"
ImageSet="Arrow s"
ShowLines="true "
ExpandDepth="1"
OnTreeNodePopul ate="TreeView1_ TreeNodePopulat e"
Runat="Server">
<Nodes>
<asp:TreeNode
Text="Messages"
Value="1"
PopulateOnDeman d="true" />
</Nodes>
</asp:TreeView>
<ASP:Table
Runat="Server"
GridLines="Hori zontal"
CellPadding="0"
CellSpacing="0"
Width="100%"
CssClass="Headi ngs"
<asp:TableRow Runat="Server" CssClass="Title ">
<ASP:TableCel l runat="Server" HorizontalAlign ="Left"
VerticalAlign=" Top">
</ASP:TableCell>
<ASP:TableCel l 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="Headi ngs">
<ASP:TableCel l runat="Server" ColumnSpan="2">
</ASP:TableCell>
</asp:TableRow>
</asp:Table>
</form>
</body>
</html>