Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Dynamic menu item

Dynamic menu item

Scheduled Pinned Locked Moved ASP.NET
xmldatabasesysadminhelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    suzzain
    wrote on last edited by
    #1

    Hi all, I have to create dynamic menus that are coming from database. Im using asp:menu control , xmldatasource and xslt file. But im not getting the menus on my page. Can anyone help me where im wrong and what should i do/ I code used is: CODE IN .ASPX <asp:Menu ID="Menu1" DataSourceID="xmlDataSource" runat="server" DynamicHorizontalOffset="2" StaticDisplayLevels="1" Orientation="Horizontal" ItemWrap="false" DynamicEnableDefaultPopOutImage="False" StaticEnableDefaultPopOutImage="False" > <DataBindings> <asp:MenuItemBinding DataMember="MenuItem" NavigateUrlField="NavigateUrl" TextField="Text" /> </DataBindings> <StaticMenuItemStyle CssClass="popup" /> <DynamicHoverStyle CssClass="popup" /> <DynamicMenuStyle CssClass="popupd" /> <DynamicSelectedStyle CssClass="popup" /> <DynamicMenuItemStyle CssClass="popupd" /> </asp:Menu> <asp:XmlDataSource ID="xmlDataSource" TransformFile="~/TransformXSLT.xsl" XPath="MenuItems/MenuItem" EnableCaching="false" runat="server"/> CODE IN ASPX.CS protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { bindMainMenu(); } } private void bindMainMenu() { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ConnectionString.ToString()); SqlCommand comm = new SqlCommand(); SqlDataAdapter da = new SqlDataAdapter(); DataSet ds = new DataSet(); conn.Open(); comm.Connection = conn; comm.CommandType = CommandType.StoredProcedure; comm.CommandText = "getMenuItems"; da.SelectCommand = comm; da.Fill(ds); ds.DataSetName = "Menus"; ds.Tables[0].TableName = "Menu"; DataRelation relation = new DataRelation("id", ds.Tables["Menu"].Columns["nodeid"], ds.Tables["Menu"].Columns["parentid"], true); relation.Nested = true; ds.Relations.Add(relation); xmlDataSource.Data = ds.GetXml(); comm.Cancel(); conn.Close(); } TransformXSLT.xsl file is &lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="xml" indent="yes" encoding="utf-8" /&gt; &lt

    C 1 Reply Last reply
    0
    • S suzzain

      Hi all, I have to create dynamic menus that are coming from database. Im using asp:menu control , xmldatasource and xslt file. But im not getting the menus on my page. Can anyone help me where im wrong and what should i do/ I code used is: CODE IN .ASPX <asp:Menu ID="Menu1" DataSourceID="xmlDataSource" runat="server" DynamicHorizontalOffset="2" StaticDisplayLevels="1" Orientation="Horizontal" ItemWrap="false" DynamicEnableDefaultPopOutImage="False" StaticEnableDefaultPopOutImage="False" > <DataBindings> <asp:MenuItemBinding DataMember="MenuItem" NavigateUrlField="NavigateUrl" TextField="Text" /> </DataBindings> <StaticMenuItemStyle CssClass="popup" /> <DynamicHoverStyle CssClass="popup" /> <DynamicMenuStyle CssClass="popupd" /> <DynamicSelectedStyle CssClass="popup" /> <DynamicMenuItemStyle CssClass="popupd" /> </asp:Menu> <asp:XmlDataSource ID="xmlDataSource" TransformFile="~/TransformXSLT.xsl" XPath="MenuItems/MenuItem" EnableCaching="false" runat="server"/> CODE IN ASPX.CS protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { bindMainMenu(); } } private void bindMainMenu() { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ConnectionString.ToString()); SqlCommand comm = new SqlCommand(); SqlDataAdapter da = new SqlDataAdapter(); DataSet ds = new DataSet(); conn.Open(); comm.Connection = conn; comm.CommandType = CommandType.StoredProcedure; comm.CommandText = "getMenuItems"; da.SelectCommand = comm; da.Fill(ds); ds.DataSetName = "Menus"; ds.Tables[0].TableName = "Menu"; DataRelation relation = new DataRelation("id", ds.Tables["Menu"].Columns["nodeid"], ds.Tables["Menu"].Columns["parentid"], true); relation.Nested = true; ds.Relations.Add(relation); xmlDataSource.Data = ds.GetXml(); comm.Cancel(); conn.Close(); } TransformXSLT.xsl file is &lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="xml" indent="yes" encoding="utf-8" /&gt; &lt

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      What makes you think you are 'going wrong' ? What do you expect, and how is this code not doing what you want ?

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      S 1 Reply Last reply
      0
      • C Christian Graus

        What makes you think you are 'going wrong' ? What do you expect, and how is this code not doing what you want ?

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        S Offline
        S Offline
        suzzain
        wrote on last edited by
        #3

        hi im not getting any errors but im not getting the menus displayed. data is coming from database. xml with relation is generated. But im not getting the menus

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups