ASP 2.0 Menu Control Fed From Database

Discussion in 'ASP .Net' started by Rob, Sep 13, 2005.

  1. Rob

    Rob Guest

    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>
     
    Rob, Sep 13, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jason
    Replies:
    0
    Views:
    288
    jason
    Feb 21, 2004
  2. ChronicFatigue

    XML content fed into a HTML page

    ChronicFatigue, Aug 21, 2003, in forum: XML
    Replies:
    1
    Views:
    408
    Andy Dingley
    Aug 22, 2003
  3. dorayme
    Replies:
    10
    Views:
    562
    Chaddy2222
    Jun 22, 2006
  4. Simon Rigby
    Replies:
    2
    Views:
    598
    Simon Rigby
    Oct 24, 2006
  5. Your Encryption Site
    Replies:
    11
    Views:
    716
    Kim André Akerø
    Apr 24, 2008
Loading...

Share This Page