Go to DotNetFunda.com
 Online : 2872 |  Welcome, Guest!   Login
 
Home > Articles > ASP.NET > Dynamic Menu using XML DataSource ASP.NET ,VB.NET

  • Nominate yourself for "Agile Software Development using Scrum" online session for FREE, click here.

  • Download OOPS and ASP.NET Online training session video and PPT from here.

Submit Article | Articles Home | Search Articles |

Dynamic Menu using XML DataSource ASP.NET ,VB.NET

 Posted on: 8/6/2008 10:55:31 PM by Majith | Views: 8215 | Category: ASP.NET | Level: Intermediate | Print Article
I am going to explain how to build dynamic menus using XMLDataSource Asp.Net ,vb.net.

.NET Training Videos!
Buy online comprehensive training video pack just for $35.00 only, see what's inside it.

Building Dynamic Menus from XMLDataSource

The ASP.NET Menu Control can have the datasource controls such as SiteMapDataSource and XMLDataSource.

Managing dynamic links,queries and controls are quite tedious  in web applications . This article expalins the way to bind the XMLDatasource control with a Menu Control.

Here I am going to describe a menu about the process in a Recruitment company  like above picture. There are two Issues in the home page.

  1. Issue1
  2. Issue2

Lets create this menu in few steps.

1. In web application  add a XML file named menu.xml. The Xml Code as follow as

<?xml version="1.0" encoding="utf-8" ?>
<HomePage>
<Menu text="Issue1" url="Issue1.aspx">
<SubMenu text="Concept1" url="Concept1.aspx"></SubMenu>
<SubMenu text="Concept2" url="Concept2.aspx"></SubMenu>
<SubMenu text="Concept3" url="Concept3.aspx"></SubMenu>
</Menu>
<Menu text="Issue2" url="Issue2.aspx">
<SubMenu text="Problem1" url="Problem1.aspx"></SubMenu>
<SubMenu text="Problem2" url="Problem2.aspx"></SubMenu>
<SubMenu text="Problem3" url="Problem3.aspx"></SubMenu>
</Menu>
</HomePage>

2. Add the XMLDataSource Control to the page from the Data tab of the Toolbox.

3. Link the DataSourceID as XmlDataSource1 for the Menu control and the menu.xml as DataFile of XmlDataSource control and bind the menu control. 

The code for menu control is

<asp:Menu ID="dymenu1" runat="server" DataSourceID="xmlsource1" Orientation="Horizontal">
<DynamicMenuStyle BackColor="#228B22" />
<StaticSelectedStyle BackColor="#FFBB77" />
<DynamicSelectedStyle BackColor="#FFAA99" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticHoverStyle BackColor="#abcdaa" Font-Bold="False" ForeColor="White" />
</asp:Menu>

The code for XmlDataSource is

<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/menu.xml"></asp:XmlDataSource>

4. Add the different styles to the Menu Control and specify  the properties such as StaticMenuItemStyle, DynamicMenuItemStyle.

5. Just run your application and you should see the menu something like picture above. Finally you have created the Dynamic Menu from XMLDataSource.

Cheers !!!


If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Interesting?   Share and Bookmark this kick it on DotNetKicks.com


About Majith Basha

Experience:0 year(s)
Home page:
Member since:Friday, July 18, 2008
Level:Starter
Status: [Member]
Biography:
 Latest post(s) from Majith

   ◘ Checking Existing Records Using Array of Data Rows posted on 4/13/2009 5:41:54 AM
   ◘ Finding Curosr Position Using JavaScript and Drag and Drop from WebControls posted on 2/24/2009 10:24:45 PM
   ◘ Reading Selected Element from XML using ASP.NET, C# posted on 11/25/2008 8:23:38 AM
   ◘ Java Script GridView ClientSide Validation posted on 9/30/2008 12:22:12 AM
   ◘ Diff Between DataGrid and GridView posted on 9/17/2008 11:20:35 PM


Submit Article

About Us | The Team | Advertise | Contact Us | Feedback | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found copied contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
All rights reserved to DotNetFunda.Com. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
(Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher)