8

我有一个简单asp:menu-item的使用Web.sitemap来获取菜单项。该页面将回发,但无法获取与单击项目关联的页面。我会提到导航条代码在母版页文件中。

<div>
  <asp:SiteMapDataSource ID="SiteMapDataSource1"  ShowStartingNode="false" runat="server" />
  <asp:Menu ID="Menu1" Orientation="horizontal"  runat="server" BackColor="#a0a080" DataSourceID="SiteMapDataSource1"
      DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#a00000"
      StaticSubMenuIndent="10px" Style="z-index: 2; left: 390px; position: absolute;
      top: 281px" Height="20px" Width="311px">
      <StaticSelectedStyle BackColor="#a0a080" />
      <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
      <DynamicHoverStyle BackColor="#a0a080" ForeColor="White" />
      <DynamicMenuStyle BackColor="#a0a080" />
      <DynamicSelectedStyle BackColor="#a0a080" />
      <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
      <DataBindings>
          <asp:MenuItemBinding DataMember="SiteMapNode" EnabledField="Title" TextField="Title" />
      </DataBindings>
      <StaticHoverStyle BackColor="#666666" ForeColor="White" />
  </asp:Menu>
</div>    

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >  
  <siteMapNode url="" title=""  description="">  
    <siteMapNode title="Home"  description="Zombie (be)Warehouse" url="index.aspx" />  
    <siteMapNode title="Armor" description="Anti-Zombie Armor" url="Armor.aspx" />  
    <siteMapNode title="Weapons" description="Anti-Zombie Weapons" url="Weapons.aspx" />  
    <siteMapNode title="Manuals" description="Survival Manuals" url="Manuals.aspx" />  
    <siteMapNode title="Sustenance" description="Prepared food for survival" url="Sustenance.aspx" />  
    <siteMapNode title="Contacts"  description="Contact Us"  url="Contacts.aspx" />  
    <siteMapNode title="About" description="About Zombie (be)Warehouse" url="About.aspx" />  
  </siteMapNode>  
</siteMap>

更新:DataBindings在菜单项 的部分中发现了问题。注意这一行:

<asp:MenuItemBinding DataMember="SiteMapNode" EnabledField="Title" Text="Title" />

从的文本字段中Text="Title"设置菜单的显示文本。Web.sitemap我注意到该MenuItemBinding项目有一个名为NavigateUrlField.

因此,要解决此问题,您只需更改/添加到asp:MenuItemBinding

<asp:MenuItemBinding DataMember="SiteMapNode" NavigateUrlField="url" EnabledField="Title" TextField="Title" />
4

1 回答 1

0

您需要将NavigateUrlField字段添加到MenuItemBinding这样 的<asp:MenuItemBinding DataMember="SiteMapNode" EnabledField="Title" TextField="Title" NavigateUrlField="url"/>

于 2019-05-26T13:06:21.610 回答