Dynamic menu item
-
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 <?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" /> <
-
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 <?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" /> <
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.
-
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.