Solved

Menu Control with XMLDataSource Issues - not horizontal and showing root node

Posted on 2013-01-28
2
568 Views
Last Modified: 2013-01-31
In VS2010 Express, the code below works, but it doesn't do two things I need it to do:

1)  Display the menu horizontally

2)  *Not* show the "Home" node (just show the menuitem entries in the XML horizontally)

Any help with this would be appreciated.

Thanks!

======page=======MenuTest01.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="MenuTest01.aspx.vb" Inherits="_Default" %>
<%@ Register TagPrefix="uc" TagName="Menu"
Src="~/MenuTestUC.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<uc:Menu ID="Menu1" runat="server" />
</form>
</body>
</html>

==========user control=========== MenuTestUC.ascx

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="MenuTestUC.ascx.vb" Inherits="WebUserControl" %>

<asp:Menu ID="Menu2" runat="server"
Orientation="Horizontal"
DisappearAfter="250"
MaximumDynamicDisplayLevels="2"
DataSourceID="XmlDataSource1">
<DataBindings>
<asp:MenuItemBinding DataMember="menuitem" NavigateUrlField="url"
TextField="Text" ValueField="Text" />
<asp:MenuItemBinding DataMember="submenuitem" NavigateUrlField="url"
TextField="Text" ValueField="Text" />
</DataBindings>
</asp:Menu>

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

========= XML File ============MenuTest02.xml

<?xml version="1.0" encoding="utf-8" ?>
<Home>
<menuitem Text="Info" url="javascript:alert('info');"/>
<menuitem Text="Map" url="">
<submenuitem Text="Show" url="javascript: alert('showmap');"/>
<submenuitem Text="Home" url="javascript: alert('map home');"/>
</menuitem>
<menuitem Text="List" url="">
<submenuitem Text="Show" url="javascript: alert('show list');"/>
<submenuitem Text="Home" url="javascript: alert('list home');"/>
</menuitem>
</Home>
0
Comment
Question by:codequest
2 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 38832071
SiteMapDataSource is a good option if you can use it.

If you have to use XML file then, do a manual databinding instead of XMLDataSource.

e.g. Your menu:
<asp:Menu ID="Menu2" runat="server"
Orientation="Horizontal"
DisappearAfter="250"
MaximumDynamicDisplayLevels="3"
StaticDisplayLevels="1">
<DataBindings>
<asp:MenuItemBinding DataMember="menuitem" NavigateUrlField="url"
TextField="Text" ValueField="Text" />
<asp:MenuItemBinding DataMember="submenuitem" NavigateUrlField="url"
TextField="Text" ValueField="Text" />
</DataBindings>
</asp:Menu>

Open in new window


PageLoad code-behind of your UC:

If Not Page.IsPostBack Then
		Dim xmlPath As String = Server.MapPath("~/MenuTest02.xml")

		Dim xmlDS As New XmlDataSource()
		xmlDS.DataFile = xmlPath
		xmlDS.XPath = "Home/menuitem"
		Menu2.DataSource = xmlDS
		Menu2.DataBind()
		Menu2.Items(0).Text = ""
		Menu2.Items(0).Value = ""
		Menu2.Items(0).Selectable = False
End If

Open in new window


Check this.
0
 
LVL 2

Author Comment

by:codequest
ID: 38842269
Works slick!  Thanks.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question