DotNet Tutorials

Server Intellect

 Controlling Menus Programmatically in ASP.NET and VB

This tutorial shows how we can use two Menu controls to display the SiteMap in a hierarchical structure. The second menu's display will depend upon the selection of the first menu. VB version. We need to create a Web.sitemap:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
<siteMapNode title="Home">
<siteMapNode title="Products">
<siteMapNode title="Hardware" url="Default.aspx?node=hardware">
<siteMapNode title="Monitors"/>
<siteMapNode title="Speakers"/>
<siteMapNode title="Input Devices"/>
<siteMapNode title="Printers"/>
<siteMapNode title="Hard Drives"/>
</siteMapNode>
<siteMapNode title="Software" url="Default.aspx?node=software">
<siteMapNode title="Operating Systems"/>
<siteMapNode title="Email"/>
<siteMapNode title="Internet"/>
<siteMapNode title="Word Processor"/>
<siteMapNode title="Database"/>
</siteMapNode>
<siteMapNode title="How-Tos" url="Default.aspx?node=howtos">
<siteMapNode title="How To Program"/>
<siteMapNode title="How To Debug"/>
<siteMapNode title="How To Test"/>
</siteMapNode>
</siteMapNode>
<siteMapNode title="Services">
<siteMapNode title="Consultation" url="Default.aspx?node=consultation">
<siteMapNode title="Processes"/>
<siteMapNode title="Management"/>
<siteMapNode title="Recruiting"/>
</siteMapNode>
<siteMapNode title="Development" url="Default.aspx?node=development">
<siteMapNode title="Web Apps"/>
<siteMapNode title="Enterprise Apps"/>
<siteMapNode title="Database"/>
</siteMapNode>
</siteMapNode>
<siteMapNode title="Support">
<siteMapNode title="Downloads" url="Default.aspx?node=downloads">
<siteMapNode title="Audio Drivers"/>
<siteMapNode title="Network Adapter Drivers"/>
<siteMapNode title="Printer Drivers"/>
<siteMapNode title="Graphics Drivers"/>
</siteMapNode>
<siteMapNode title="Manuals" url="Default.aspx?node=manuals">
<siteMapNode title="Applications"/>
<siteMapNode title="Troubleshooting"/>
<siteMapNode title="Installation"/>
<siteMapNode title="Internet"/>
</siteMapNode>
</siteMapNode>
</siteMapNode>
</siteMap>

We migrated our web sites to Server Intellect over one weekend and the setup was so smooth that we were up and running right away. They assisted us with everything we needed to do for all of our applications. With Server Intellect's help, we were able to avoid any headaches!


There are two SiteMapDataSources; one for the first menu, and one for the second menu. The second SiteMapDataSource has the StartingNodeUrl set to
Default.aspx?node=hardware
The ASPX code:

<form id="form1" runat="server">
<div>
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" MaximumDynamicDisplayLevels="0" OnMenuItemClick="Menu1_MenuItemClick" Orientation="Horizontal">
<DataBindings>
<asp:MenuItemBinding DataMember="SiteMapNode" TextField="Title" />
</DataBindings>
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" />
<br />
<asp:Menu ID="Menu2" runat="server" DataSourceID="SiteMapDataSource2" Orientation="Horizontal">
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource2" runat="server" ShowStartingNode="False" StartingNodeOffset="-1" StartingNodeUrl="Default.aspx?node=hardware" />
<br />
<br />
</div>
</form>

The VB code for the Click event for the first menu should look something like this:

If you're ever in the market for some great Windows web hosting, try Server Intellect. We have been very pleased with their services and most importantly, technical support.

Protected Sub Menu1_MenuItemClick(ByVal sender As Object, ByVal e As MenuEventArgs)
Select Case e.Item.Value
Case "Products"
SiteMapDataSource2.StartingNodeUrl = "Default.aspx?node=hardware"
Return
Case "Services"
SiteMapDataSource2.StartingNodeUrl = "Default.aspx?node=consultation"
Return
Case "Support"
SiteMapDataSource2.StartingNodeUrl = "Default.aspx?node=downloads"
Return
End Select
End Sub



Looking for the C#.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!
Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!
 
123 ASP

411 ASP

Dot Net Freaks

Server Intellect