以编程方式删除子菜单项

时间:2013-01-10 19:38:34

标签: asp.net vb.net menu menuitem

我需要隐藏一些菜单项,但我不知道如何。

我从web.siteMap xml文件中获取数据,因为它是一个站点地图,我已经在我的网站中包含了所有页面。问题是,其中一些页面需要一个查询字符串才能正常运行;而且我不想告诉用户他在错误的页面上,因为他从菜单中点击了一个他不应该拥有的项目。所以我决定隐藏这些页面。

编辑:我想删除:

<siteMapNode url="~/Categories/review_tab.aspx" title="TABLET REVIEWS" description="TABLET REVIEWS"/>
<siteMapNode url="~/Categories/review_lap.aspx" title="LAPTOP REVIEWS" description="LAPTOP REVIEWS"/>
<siteMapNode url="~/Categories/review_tab.aspx" title="TABLET REVIEWS" description="TABLET REVIEWS"/>
<siteMapNode url="~/Categories/review_cam.aspx" title="CAMERA REVIEWS" description="CAMERA REVIEWS"/>

站点地图的结构如下:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="~/" title="Menu"  description="Menu">
        <siteMapNode url="~/Default.aspx" title="HOME"  description="HOME"></siteMapNode>
        <siteMapNode url="~/ContactUs.aspx" title="CONTACT US" description="CONTACT US" />
        <siteMapNode url="~/About.aspx" title="ABOUT US" description="ABOUT US" />
        <siteMapNode url="~/Members/Default.aspx" title="MEMBERS" description="MEMBERS">
            <siteMapNode url="~/Members/ChangePassword.aspx" title="CHANGE PASSWORD" description="CHANGE PASSWORD" />
        </siteMapNode>
        <siteMapNode url="~/login.aspx" title="REVIEWS"  description="REVIEWS">
            <siteMapNode url="~/Categories/Laptops.aspx" title="LAPTOP" description="LAPTOP"/>
            <siteMapNode url="~/Categories/review_lap.aspx" title="LAPTOP REVIEWS" description="LAPTOP REVIEWS"/>
            <siteMapNode url="~/Categories/Smartphones.aspx" title="SMARTPHONE" description="SMARTPHONE"/>
            <siteMapNode url="~/Categories/review_smart.aspx" title="SMARTPHONE REVIEWS" description="SMARTPHONE REVIEWS"/>
            <siteMapNode url="~/Categories/Tablets.aspx" title="TABLETS" description="TABLETS"/>
            <siteMapNode url="~/Categories/review_tab.aspx" title="TABLET REVIEWS" description="TABLET REVIEWS"/>
            <siteMapNode url="~/Categories/Cameras.aspx" title="CAMERAS" description="CAMERAS"/>
            <siteMapNode url="~/Categories/review_cam.aspx" title="CAMERA REVIEWS" description="CAMERA REVIEWS"/>
        </siteMapNode>
        <siteMapNode url="~/Account/Default.aspx" title="ACCOUNT" description="ACCOUNT">
          <siteMapNode url="~/Account/Register.aspx" title="REGISTER" description="REGISTER"/>
          <siteMapNode url="~/Account/ForgotPassword.aspx" title="FORGOT PASS" description="FORGOT PASS" />
        </siteMapNode>
        <siteMapNode url="~/Administrator/Default.aspx" title="ADMIN"  description="ADMIN ">
          <siteMapNode url="~/Administrator/Laptops.aspx" title="LAPTOP" description="LAPTOP"/>
          <siteMapNode url="~/Administrator/Smartphones.aspx" title="SMARTPHONE" description="SMARTPHONE"/>
          <siteMapNode url="~/Administrator/Tablets.aspx" title="TABLETS" description="TABLETS"/>
          <siteMapNode url="~/Administrator/Cameras.aspx" title="CAMERAS" description="CAMERAS"/>
        </siteMapNode>
    </siteMapNode>
</siteMap>

菜单:

.
.
.
<div id="menu_div" align="left" dir="ltr">
    <asp:Menu ID="Menu1" runat="server" BackColor="#C0BFBD" 
        DataSourceID="SiteMapDataSource1" DynamicHorizontalOffset="2" 
        Font-Names="Calibri" Font-Size="Medium" ForeColor="#2C2F36" 
        StaticSubMenuIndent="10px" RenderingMode="Table" 
        StaticEnableDefaultPopOutImage="False" style="margin-right: 0px" 
        Font-Bold="True" DisappearAfter="200">
        <DynamicHoverStyle BackColor="#282B32" ForeColor="White" />
        <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="3px" />
        <DynamicMenuStyle BackColor="#B5C7DE" />
        <DynamicSelectedStyle BackColor="Gray" />
        <DynamicItemTemplate>
            <%# Eval("Text") %>
        </DynamicItemTemplate>
        <StaticHoverStyle BackColor="#284E98" ForeColor="White" />
        <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="5px" />
        <StaticSelectedStyle BackColor="#70788B" />
    </asp:Menu>
    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" 
        ShowStartingNode="False" />
</div>

0 个答案:

没有答案