ASP.NET Slide Menu Tutorial - From database

Menu can be easily populated from the database. Following are the table and menu used for this example:

ID Title ParentId
0 Fruit -1
1 Apple 0
2 Orange 0
3 Pear 0
4 Banana 0
5 Cars -1
6 Ford 5
7 Chevy 5
8 Mercury 5
9 Aston Martin 5
10 Volvo 5
11 Cities -1
12 New York 11
13 Chicago 11
14 San Francisco 11
15 Los Angeles 11
16 Miami 11

For classic ASP, please download this example: classicASPDB.zip

For .NET, this example with access database is available in NETDB.zip


.NET
<%@ Page Language="C#" %>
<%@ Register TagPrefix="osm" Namespace="OboutInc.SlideMenu" Assembly="obout_SlideMenu3_Pro_Net" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script runat="server">

    void Page_Load(object o, EventArgs e) {
        OleDbConnection conn = null;
        OleDbDataReader reader = null;
        
        conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " + "Data Source=" 
        + Server.MapPath("menu.mdb"));
        conn.Open();

        OleDbCommand cmd = new OleDbCommand("SELECT * FROM MenuItems ORDER BY ParentId, ID", conn);
        reader = cmd.ExecuteReader();

        while(reader.Read()) {

            if(reader["ParentId"].ToString().Equals("-1"))
                myMenu.AddParent("p" + reader["ID"].ToString(),reader["Title"].ToString());
            else
                myMenu.AddChildAt("c" + reader["ID"].ToString(), "p" + reader["ParentId"].ToString(),
                reader["Title"].ToString(), 
                                              null, null, null);

        }
        
        reader.Close();
        conn.Close();
    }

</script>

<osm:SlideMenu runat="server" ID="myMenu" StyleFolder="/slidemenu/styles/pro_5" />