Click here to Skip to main content
15,888,351 members
Articles / Web Development / HTML
Article

ASP.NET Dynamic XML Web Menu Control based on JavaScript

Rate me:
Please Sign up or sign in to vote.
4.00/5 (30 votes)
22 Sep 20052 min read 440.9K   7K   92   105
ASP.NET dynamic XML web menu control based on JavaScript.

Image 1

Introduction

This is a free web based menu (JavaScript enabled) control. There are not many web menu controls available that support dynamic menu creation and binding. This WebMenu control supports dynamic menu creation, XML menu binding and also DataSet binding. This control uses triga (free script) JavaScript menu internally. Any complex menu structure can be represented using a simple XML schema. Menu position and style can be easily applied and changed dynamically without affecting the web application.

Steps to setup WebMenu

  1. Create a new ASP.NET web project, right click on ToolBox; choose 'Add/Remove items' and add the SuperControls.WebMenu.dll reference (compile SuperControls.WebMenu.cproj to get the DLL).
  2. Copy the JS files menu_tpl.js and menu.js to the root directory of the site.
  3. Copy menu stylesheet menu.css file to the subdirectory css.
  4. Copy menudata.xml to the root directory.
  5. Create an ASPX file and drag and drop the WebMenu control to the WebForm and use one of the methods (given below) to bind the XML/dynamic data to the menu control.

ASPX Code

HTML
<cc1:WebMenu id="WebMenu1" MenuXMLPath="\\ServerName\rad\menudata.xml" 
                                        PadWidth="24" runat="server">
</cc1:WebMenu>
<!--
Other samples
//**********************************************************************
<cc1:WebMenu id="WebMenu2" MenuXMLPath="ServerName\rad\menudata.xml" 
                      ImageArrow="<img src=images\\arrow.gif border=0" 
                      PadWidth="22" runat="server">
</cc1:WebMenu>
<cc1:WebMenu id="WebMenu3" MenuXMLPath="\\ServerName\rad\menudata.xml" 
                           ImageArrow="" PadWidth="26" runat="server">
</cc1:WebMenu>
-->

Ways of binding menu items dynamically...

Method 1

Set MenuXMLPath property with the path of the XML menu file in the server.

Method 2

Create new DataSet with the XML file and bind to the web menu control.

For example:

C#
DataSet dsMenu = new DataSet();
dsMenu.ReadXml(@"\\ServerName\rad\menudata.xml");
WebMenu1.DataSource = dsMenu;

Method 3

Get the menu data from database and populate the DataSet with the following structure:

  • Column 1 : menuid (unique ID of menu item).
  • Column 2 : name (name of the menu item).
  • Column 3 : root (parent of the menu item. If it is the starting/root item then the root value will be "" else it will be the value of the parent menuid).
  • Column 4 : url (URL for the menu item).

For example:

C#
WebMenu1.DataSource = dsMenu;
// (Sample DataSet is given below.)

XML menu file (sample)

XML
<?xml version="1.0" encoding="utf-8" ?> 
<menu>
    'Level 0 nodes
    <menuitem root="" name="Search Sites" menuid="1" />
    <menuitem root="" name="Webmail Sites"  menuid="2" />
    <menuitem root="" name="DotNet Sites"  menuid="3" />
    
    'Level 1 Items
    <menuitem root="1" name="Google" url="http://www.google.com" 
                                                        menuid="11"/>
    <menuitem root="1" name="Altavista" url="http://www.Altavista.com" 
                                                        menuid="12"/>
    
    'Level 1 Items
    <menuitem root="2" name="Hot-mail" url=""  menuid="21"/>
        'Level 2 Items
        <menuitem root="21" name="Hotmail" url="http://www.hotmail.com" 
                                                          menuid="211"/>
        <menuitem root="21" name="MSN" url="http://www.MSN.com" 
                                                          menuid="212"/>
        
    <menuitem root="2" name="Yahoo" url="http://www.yahoo.com" 
                                                           menuid="22"/>
    <menuitem root="2" name="Rediff" url="http://www.rediff.com" 
                                                           menuid="23"/>
    
    'Level 1 Items
    <menuitem root="3" name="Microsoft" url="http://www.Microsoft.com" 
                                                           menuid="31"/>
    <menuitem root="3" name="GotDotNet" url="http://www.GotDotNet.com" 
                                                           menuid="32"/>
    <menuitem root="3" name="CodeProject" url="http://www.CodeProject.com" 
                                                           menuid="33"/>
    <menuitem root="3" name="ASpdotnet" url="http://www.ASpdotnet.com" 
                                                           menuid="34"/>
    
</menu>

In the above sample, the root attribute represents the parent of the menu item. The root attribute will be empty for parent/level zero menu items.

Sample dynamic menu DataSet (with one DataTable)

rootnamemenuidurl
Search Sites1
Webmail Sites2
DotNet Sites3
1Google11http://www.google.com
1Altavista12http://www.Altavista.com
2Hot-mail21
21Hotmail211http://www.hotmail.com
21MSN212http://www.MSN.com
2Yahoo22http://www.yahoo.com
2Rediff23http://www.rediff.com
3Microsoft31http://www.Microsoft.com
3GotDotNet32http://www.GotDotNet.com
3CodeProject33http://www.CodeProject.com
3ASpdotnet34http://www.ASpdotnet.com

License

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


Written By
United Arab Emirates United Arab Emirates
Software Engineer from India,Working in .NET for 2 years.

Comments and Discussions

 
GeneralI don't see anything either. Pin
Grondal17-Nov-06 1:03
Grondal17-Nov-06 1:03 
GeneralDont see anything... Pin
keng15099-Nov-06 17:05
keng15099-Nov-06 17:05 
GeneralVertical Menu Pin
csgraham17-Oct-06 9:23
csgraham17-Oct-06 9:23 
Generaljust want to said thank you Pin
tarikelmallah16-Oct-06 9:45
tarikelmallah16-Oct-06 9:45 
QuestionUsing different images for each menu? Pin
saeed_amd20-Sep-06 22:34
saeed_amd20-Sep-06 22:34 
QuestionHow to position the menu inside a table cell Pin
reza55311-Sep-06 4:36
reza55311-Sep-06 4:36 
AnswerRe: How to position the menu inside a table cell Pin
Kountree9-Oct-06 10:00
Kountree9-Oct-06 10:00 
AnswerCan not see any menu when we diployee our application in IIS 7 server ......... Pin
vikas197610-Dec-09 23:12
vikas197610-Dec-09 23:12 
AnswerCan not see any menu when we diployee our application in IIS 7 server . pls help Pin
vikas197610-Dec-09 23:13
vikas197610-Dec-09 23:13 
QuestionHow to have the menu items overlap the other frame Pin
KUNAL9931-Aug-06 9:05
KUNAL9931-Aug-06 9:05 
QuestionHow to change the image in menu control Pin
KUNAL9931-Aug-06 8:29
KUNAL9931-Aug-06 8:29 
AnswerRe: How to change the image in menu control Pin
KUNAL9931-Aug-06 8:57
KUNAL9931-Aug-06 8:57 
Questioni wanna insert/edit/delete datas in the xml file,but...... Pin
daybug25-Aug-06 17:37
daybug25-Aug-06 17:37 
Generaloverlapping menu with listbox/dropdowns Pin
lil_evil2-Jul-06 18:37
lil_evil2-Jul-06 18:37 
GeneralRe: overlapping menu with listbox/dropdowns Pin
psamy2-Jul-06 19:17
psamy2-Jul-06 19:17 
GeneralRe: overlapping menu with listbox/dropdowns Pin
lil_evil3-Jul-06 10:21
lil_evil3-Jul-06 10:21 
GeneralRe: overlapping menu with listbox/dropdowns Pin
Paras Shah14-Nov-06 2:17
Paras Shah14-Nov-06 2:17 
GeneralRe: overlapping menu with listbox/dropdowns Pin
Speed_up29-Nov-07 5:08
Speed_up29-Nov-07 5:08 
QuestionCan crossover frame page? Pin
Q_Quek2-Apr-06 23:58
Q_Quek2-Apr-06 23:58 
GeneralUseless control Pin
RakeshSaini1234530-Mar-06 0:37
RakeshSaini1234530-Mar-06 0:37 
GeneralRe: Useless control Pin
Kountree9-Oct-06 10:00
Kountree9-Oct-06 10:00 
GeneralUnable to see Pin
RakeshSaini1234530-Mar-06 0:33
RakeshSaini1234530-Mar-06 0:33 
Generali am unable to see menu Pin
RakeshSaini1234529-Mar-06 23:51
RakeshSaini1234529-Mar-06 23:51 
Questionvertical menu Pin
Shennawy2-Dec-05 7:14
Shennawy2-Dec-05 7:14 
QuestionRight to Left menus Pin
Shennawy2-Dec-05 7:12
Shennawy2-Dec-05 7:12 

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.