Click here to Skip to main content
15,921,841 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

Forgive me I can not write good English.


The following menu items that do not want just anyone have a link to the page.
But those who have sub-menu click on them nothing happens.
Below you can see my code
Please help me with changing it.


Menu.aspx.cs
C#
DataSet ds = new DataSet();
string connStr = @"Data Source=.;Initial Catalog=Azad;Integrated Security=True";
using (SqlConnection conn = new SqlConnection(connStr))
{
    string sql = "Select MenuID, Text, Description, ParentID from Menu";
    SqlDataAdapter da = new SqlDataAdapter(sql, conn);
    da.Fill(ds);
    da.Dispose();
}
ds.DataSetName = "Menus";
ds.Tables[0].TableName = "Menu";
DataRelation relation = new DataRelation("ParentChild",
        ds.Tables["Menu"].Columns["MenuID"],
        ds.Tables["Menu"].Columns["ParentID"],
        true);

relation.Nested = true;
ds.Relations.Add(relation);


Menu.aspx
ASP.NET
<form id="form1"  runat="server">
    <div>
       <asp:Menu ID="Menu1" DataSourceID="xmlDataSource" runat="server" 
          BackColor="#FFFBD6" DynamicHorizontalOffset="2" Font-Names="Verdana" 
          ForeColor="#990000" StaticSubMenuIndent="10px" StaticDisplayLevels="1" Orientation="Horizontal">
          <DataBindings>
            <asp:MenuItemBinding DataMember="MenuItem" 
             NavigateUrlField="NavigateUrl" TextField="Title" />
          </DataBindings>
          <StaticSelectedStyle BackColor="#FFCC66" />
          <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
          <DynamicMenuStyle BackColor="#FFFBD6" />
          <DynamicSelectedStyle BackColor="#FFCC66" />
          <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
          <DynamicHoverStyle BackColor="#990000" Font-Bold="False" ForeColor="White"/>
          <StaticHoverStyle BackColor="#990000" Font-Bold="False" ForeColor="White" />
       </asp:Menu>
       <asp:XmlDataSource ID="xmlDataSource" TransformFile="~/TransformXSLT.xsl"  
          XPath="MenuItems/MenuItem" runat="server" EnableCaching="False" 
            EnableViewState="False"/> 
    </div>
    </form>


TransformXSLT.xsl
XML
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes" encoding="utf-8"/>
  <!-- Find the root node called Menus 
       and call MenuListing for its children -->
  <xsl:template match="/Menus">
    <MenuItems>
      <xsl:call-template name="MenuListing" />
    </MenuItems>
  </xsl:template>
  
  <!-- Allow for recusive child node processing -->
  <xsl:template name="MenuListing">
    <xsl:apply-templates select="Menu" />
  </xsl:template>
  
  <xsl:template match="Menu">
    <MenuItem>
      <!-- Convert Menu child elements to MenuItem attributes -->
      <xsl:attribute name="Title">
        <xsl:value-of select="Title"/>
      </xsl:attribute>
		
      <!--<xsl:attribute name="ToolTip">
        <xsl:value-of select="Description"/>
      </xsl:attribute>-->
		
      <xsl:attribute name="NavigateUrl">
        <xsl:text>?Sel=</xsl:text>
        <xsl:value-of select="ID"/>
      </xsl:attribute>
      
      <!-- Call MenuListing if there are child Menu nodes -->
      <xsl:if test="count(Menu) > 0">
		  <xsl:call-template name="MenuListing" />
      </xsl:if>
    </MenuItem>
  </xsl:template>
</xsl:stylesheet>
Posted

1 solution

I THINK you want to show the options but not have them work for some users. I am not sure an XSLT can do this, unless you insert attributes the XSLT can look for. The alternative is to just strip the URLs for the pages you don't want to work, from the XML you pass in to the XSLT.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900