我正在构建我的第一个 asp.net 应用程序,我插入了菜单控件(水平)并将其绑定到我制作的 XML 文件。不幸的是,在呈现页面时,菜单显示名为 SubMenu、SubMenu、SubMenu 的子项,并且我的文本属性未应用,链接也始终指向 #。我在网上查看了其他人的代码,我无法发现差异。代码:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="OuterShell.master.cs" Inherits="OuterShell" %>
<!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>
<link href="~/Styles/style1.css" rel="Stylesheet" type="text/css" />
<asp:ContentPlaceHolder id="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<asp:Menu ID="Menu1" runat="server" DataSourceID="XmlDataSource1"
Orientation="Horizontal" BackColor="#F7F6F3" DynamicHorizontalOffset="2"
Font-Names="Verdana" Font-Size="0.8em" ForeColor="#7C6F57"
StaticSubMenuIndent="10px">
<DynamicHoverStyle BackColor="#7C6F57" ForeColor="White" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicMenuStyle BackColor="#F7F6F3" />
<DynamicSelectedStyle BackColor="#5D7B9D" />
<DynamicItemTemplate>
<%# Eval("Text") %>
</DynamicItemTemplate>
<StaticHoverStyle BackColor="#7C6F57" ForeColor="White" />
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<StaticSelectedStyle BackColor="#5D7B9D" />
</asp:Menu>
<asp:XmlDataSource ID="XmlDataSource1" runat="server"
DataFile="~/App_Data/menu_h.xml" EnableCaching="False"></asp:XmlDataSource>
<div>
<asp:ContentPlaceHolder id="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
XML 代码:
<Main Text="Main Menu" url="~/Main.aspx">
<SubMenu Text="Start Configuring" url="~/Config1.aspx"></SubMenu>
<SubMenu Text="About Us" url="~/About.aspx"></SubMenu>
<SubMenu Text="Contact Us" url="~/Contact.aspx"></SubMenu>
</Main>
任何帮助表示赞赏。谢谢。