Dynamic menu Child nodes not expanding

2 posts, 0 answers
  1. Purojit
    Purojit avatar
    26 posts
    Member since:
    Jun 2013

    Posted 17 Jun 2013 Link to this post

    Hi,

    I am trying to use dynamic rad-menu in our application. I am following the code mentioned in telerik.com mentioned in the link below:
    http://www.telerik.com/help/aspnet-ajax/panelbar-dynamically-created-radmenu.html
    The problem is that the submenu side is not expanding instead it is showing at the rightmost part of parent nodes.
    For reference I post my code below.
    .aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="mymenu3.aspx.cs" Inherits="Presentationlayer_mymenu3" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>MyMenu</title>
    </head>
    <body>
         <form id="form2" runat="server">
       <asp:ScriptManager ID="ScriptManager1" runat="server">
       </asp:ScriptManager>
       <telerik:RadPanelBar ID="RadPanelBar1" runat="server" Skin="Web20" Width="190px">
           <Items>
               <telerik:RadPanelItem runat="server" Text="Root Panel Item" Expanded="true" Selected="true">
                   <Items>
                       <telerik:RadPanelItem runat="server" Value="templateHolder">
                       </telerik:RadPanelItem>
                   </Items>
               </telerik:RadPanelItem>
           </Items>
           
           <CollapseAnimation Duration="100" Type="None" />
           <ExpandAnimation Duration="100" Type="None" />
       </telerik:RadPanelBar>
    </form>
    </body>
    </html>

    .aspx.cs
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Web.Configuration;
    using System.Data.SqlClient;
    using System.Globalization;
    using Telerik.Web.UI;


    public partial class Presentationlayer_mymenu3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //SqlConnection connec = new SqlConnection(@"Data Source=sharedmssql.znetindia.net,1235;Initial Catalog=abatech_primus;User ID=abatechadmin;Password=abatechweb123");
                //connec.Open();
                SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM myMenuLinks", ConfigurationManager.ConnectionStrings["abatech_primusConnectionString"].ConnectionString);
                DataSet links = new DataSet();
                adapter.Fill(links);
                DataTable dt = new DataTable();
                dt = links.Tables[0];
                RadPanelItem panelItem = (RadPanelItem)RadPanelBar1.FindItemByValue("templateHolder");
                RadMenu myMenu = new RadMenu();
                myMenu.Width = Unit.Percentage(100);
                myMenu.Skin = "Web20";
                myMenu.Flow = ItemFlow.Vertical;
                myMenu.DataTextField = "Title";
                myMenu.DataFieldID = "CategoryId";
                myMenu.DataFieldParentID = "ParentId";
                myMenu.DataSource = dt;
                myMenu.DataBind();
                panelItem.Controls.Add(myMenu);

                foreach (RadMenuItem myItems in myMenu.GetAllItems())
                {
                    myItems.Width = Unit.Percentage(100);
                }
            }
           
        }
    }

    Attaching the screen shot also for reference.

    Thanks & Regards
    Purojit
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 17 Jun 2013 Link to this post

    Hello,

    Please try with below code snippet.
    <telerik:RadPanelBar ID="RadPanelBar1" runat="server" Skin="Web20" Width="190px">
            <Items>
                <telerik:RadPanelItem runat="server" Text="Root Panel Item" Expanded="true" Selected="true">
                    <Items>
                        <telerik:RadPanelItem runat="server" Value="templateHolder">
                        </telerik:RadPanelItem>
                    </Items>
                </telerik:RadPanelItem>
            </Items>
            <CollapseAnimation Duration="100" Type="None" />
            <ExpandAnimation Duration="100" Type="None" />
        </telerik:RadPanelBar>
    protected void Page_Load(object sender, System.EventArgs e)
       {
           DataTable dt = new DataTable();
           dt.Columns.Add("ParentId", typeof(int));
           dt.Columns.Add("CategoryId", typeof(int));
           dt.Columns.Add("Title", typeof(string));
     
           dt.Rows.Add(null,1,"1");
           dt.Rows.Add(null,2,"2");
           dt.Rows.Add(1,3,"3");
           dt.Rows.Add(1,4,"4");
           dt.Rows.Add(2,5,"5");
           dt.Rows.Add(3, 6, "6");
     
           RadPanelItem panelItem = (RadPanelItem)RadPanelBar1.FindItemByValue("templateHolder");
           RadMenu myMenu = new RadMenu();
            
           myMenu.Flow = ItemFlow.Vertical;
           myMenu.DataTextField = "Title";
           myMenu.DataFieldID = "CategoryId";
           myMenu.DataFieldParentID = "ParentId";
           myMenu.DataSource = dt;
           myMenu.DataBind();
           panelItem.Controls.Add(myMenu);
     
       }


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top