Click here to Skip to main content
12,698,939 members (23,739 online)
Click here to Skip to main content
Add your own
alternative version


54 bookmarked

Database Driven HTML popup menu

, 27 Oct 2005
Rate this:
Please Sign up or sign in to vote.
An article on how to generate an HTML popup menu from a database.

Sample Image


A while ago my boss approached me to do a content management system for a company that wanted to have drop down menus for sub-links on their websites. I went on the net to try and find a control that could make me easily achieve that but to my surprise I found nothing! This inspired me to write a Dreamweaver like popup menu control that gets parent and child nodes from the database and creates a JavaScript drop down menu just like the one you get in the Macromedia Dreamweaver.

Using the code

I created a class library (attached) that has two classes. The class dvstories returns a DataView of the main/sub pages listing. The second, buildmenu - returns a string with JavaScript for building the parent and child nodes of the menu.

In the header file for all my .aspx pages - top.ascx - I construct a string to raise the MouseOver event for the menus to popup. I also hard-coded (for this version) the menu dimensions which determine where the menu is displayed:

//mouseover event
//refer to mm_menu.js to understand the variables
string mnustr = "onMouseOver=\"MM_showMenu(window.mnmenu," + 
       "x,138,null,'image2')\" onMouseOut=\"MM_startTimeout();\"";
sect2 = "";
sect3 = "";
sect4 = "";
sect6 = "";
//location of menu - y axis
int x = 160;

    DataView dvmainlist = new DataView();
    DataView subs = new DataView();

    dvmainlist = dp.dvstories(1);

    //start building menu children from parent nodes
    //also puts in dimensions of the menu dropdown....

    foreach (DataRow r in dvmainlist.Table.Rows)
        string mainuid = r["main_pgID"].ToString();
        if (Convert.ToInt32(mainuid) != dp.sub_id)
            subs = fillchild("2");

            if (subs.Table.Rows.Count >= 1 )
                sect2 = mnustr.Replace("mnmenu", "mm_menu_2_0");
                sect2 = sect2.Replace("x", x.ToString());

            subs = fillchild("3");

            if (subs.Table.Rows.Count >= 1 )
                sect3 = mnustr.Replace("mnmenu", "mm_menu_3_0");
                //location of menu - y-axis
                sect3 = sect3.Replace("x", (x + 185).ToString());

            subs = fillchild("4");

            if (subs.Table.Rows.Count >= 1 )
                sect4 = mnustr.Replace("mnmenu", "mm_menu_4_0");
                sect4 = sect4.Replace("x", (x + 290).ToString());

            subs = fillchild("6");

            if (subs.Table.Rows.Count >= 1 )
                sect6 = mnustr.Replace("mnmenu", "mm_menu_6_0");
                sect6 = sect6.Replace("x",(x + 300).ToString());

catch (Exception ex)

Within the HTML section of the actual .aspx (default.aspx), for the example page, I had to put the following code:

<!--put this within the head tag -->
<script language="JavaScript">
function mmLoadMenus() {

In the code-behind file, you have to call the buildmenu class from the component in order to retain the menu content string.


I am currently working on making this a control fully customizable - attributes like back ground color, x,y position etc. Any help is very much appreciated.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
South Africa South Africa
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralConnecting the menu to a different database Pin
b0rnslipy7-Jul-08 22:42
memberb0rnslipy7-Jul-08 22:42 
GeneralDiplaying database (in C#) in website (in html) Pin
22teddy2226-Mar-07 8:37
member22teddy2226-Mar-07 8:37 
Generaldrop down lists Pin
eli_b22-May-06 7:48
membereli_b22-May-06 7:48 
GeneralRe: drop down lists Pin
Mugombi25-May-06 3:49
memberMugombi25-May-06 3:49 
GeneralQuestion about positioning Pin
jacobstrix4-May-06 20:44
memberjacobstrix4-May-06 20:44 
GeneralRe: Question about positioning Pin
Mugombi8-May-06 7:15
memberMugombi8-May-06 7:15 
Generaltop.ascx does not work Pin
SergeiT6-Dec-05 11:08
memberSergeiT6-Dec-05 11:08 
GeneralRe: top.ascx does not work Pin
SergeiT6-Dec-05 12:32
memberSergeiT6-Dec-05 12:32 
GeneralExcellent Menu Pin
metweek4-Nov-05 10:48
membermetweek4-Nov-05 10:48 
GeneralThere is already a good component for this :-) Pin
pnr1-Nov-05 20:55
memberpnr1-Nov-05 20:55 
GeneralRe: There is already a good component for this :-) Pin
Mugombi2-Nov-05 22:41
memberMugombi2-Nov-05 22:41 
GeneralRe: There is already a good component for this :-) Pin
pnr2-Nov-05 23:10
memberpnr2-Nov-05 23:10 
GeneralRe: There is already a good component for this :-) Pin
Mugombi3-Nov-05 0:31
memberMugombi3-Nov-05 0:31 
GeneralRe: There is already a good component for this :-) Pin
Nazf9-Nov-05 11:54
memberNazf9-Nov-05 11:54 
GeneralRe: There is already a good component for this :-) Pin
Mugombi10-Nov-05 2:06
memberMugombi10-Nov-05 2:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 27 Oct 2005
Article Copyright 2005 by Mugombi
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid