![]() |
Web Development »
Custom Controls »
General
Intermediate
ASP.NET Dynamic XML Web Menu Control based on JavaScriptBy Krishna_accentASP.NET dynamic XML web menu control based on JavaScript. |
C#, Javascript.NET 1.0, Win2K, WinXP, Win2003, Vista, ASP.NET, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

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.
WebMenu control to the WebForm and use one of the methods (given below) to bind the XML/dynamic data to the menu control. <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>
-->
Set MenuXMLPath property with the path of the XML menu file in the server.
Create new DataSet with the XML file and bind to the web menu control.
For example:
DataSet dsMenu = new DataSet();
dsMenu.ReadXml(@"\\ServerName\rad\menudata.xml");
WebMenu1.DataSource = dsMenu;
Get the menu data from database and populate the DataSet with the following structure:
menuid (unique ID of menu item).
name (name of the menu item).
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).
url (URL for the menu item). For example:
WebMenu1.DataSource = dsMenu;
// (Sample DataSet is given below.)
<?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.
root |
name |
menuid |
url |
| Search Sites | 1 | ||
| Webmail Sites | 2 | ||
| DotNet Sites | 3 | ||
| 1 | 11 | http://www.google.com | |
| 1 | Altavista | 12 | http://www.Altavista.com |
| 2 | Hot-mail | 21 | |
| 21 | Hotmail | 211 | http://www.hotmail.com |
| 21 | MSN | 212 | http://www.MSN.com |
| 2 | Yahoo | 22 | http://www.yahoo.com |
| 2 | Rediff | 23 | http://www.rediff.com |
| 3 | Microsoft | 31 | http://www.Microsoft.com |
| 3 | GotDotNet | 32 | http://www.GotDotNet.com |
| 3 | CodeProject | 33 | http://www.CodeProject.com |
| 3 | ASpdotnet | 34 | http://www.ASpdotnet.com |
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 22 Sep 2005 Editor: Smitha Vijayan |
Copyright 2005 by Krishna_accent Everything else Copyright © CodeProject, 1999-2009 Web19 | Advertise on the Code Project |