Solved

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

Posted on 2013-01-28
2
565 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

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.…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

770 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