New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

RadPanelBar with Dynamically Created RadMenu

The sample code below shows how to dynamically create Radmenu inside a RadPanelItem template.

<form id="form2" runat="server">
   <asp:ScriptManager ID="ScriptManager1" runat="server">
   <telerik:RadPanelBar RenderMode="Lightweight" ID="RadPanelBar1" runat="server" Skin="Outlook" Width="190px">
           <telerik:RadPanelItem runat="server" Text="Root Panel Item" Expanded="true" Selected="true">
                   <telerik:RadPanelItem runat="server" Value="templateHolder">
       <CollapseAnimation Duration="100" Type="None" />
       <ExpandAnimation Duration="100" Type="None" />

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;

public partial class _Default : System.Web.UI.Page
   protected void Page_Load(object sender, EventArgs e)
       if (!IsPostBack)
           SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM myMenuLinks", ConfigurationManager.ConnectionStrings["TestDBConnectionString"].ConnectionString);
           DataSet links = new DataSet();
           RadPanelItem panelItem = (RadPanelItem)RadPanelBar1.FindItemByValue("templateHolder");
           RadMenu myMenu = new RadMenu();
           myMenu.Width = Unit.Percentage(100);
           myMenu.Skin = "Outlook";
           myMenu.Flow = ItemFlow.Vertical;
           myMenu.DataTextField = "Title";
           myMenu.DataFieldID = "CategoryId";
           myMenu.DataFieldParentID = "ParentId";
           myMenu.DataSource = links;
           foreach (RadMenuItem myItems in myMenu.GetAllItems())
               myItems.Width = Unit.Percentage(100);

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Telerik.Web.UI
    Partial Public Class _Default
        Inherits System.Web.UI.Page
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            If Not IsPostBack Then
                Dim adapter As New SqlDataAdapter("SELECT * FROM myMenuLinks", ConfigurationManager.ConnectionStrings("TestDBConnectionString").ConnectionString)
                Dim links As New DataSet()
                Dim panelItem As RadPanelItem = DirectCast(RadPanelBar1.FindItemByValue("templateHolder"), RadPanelItem)
                Dim myMenu As New RadMenu()
                myMenu.Width = Unit.Percentage(100)
                myMenu.Skin = "Outlook"
                myMenu.Flow = ItemFlow.Vertical
                myMenu.DataTextField = "Title"
                myMenu.DataFieldID = "CategoryId"
                myMenu.DataFieldParentID = "ParentId"
                myMenu.DataSource = links
                For Each myItems As RadMenuItem In myMenu.GetAllItems()
                    myItems.Width = Unit.Percentage(100)
            End If
        End Sub
    End Class

myMenuLinkis SQL Table:

Panelbar With Menu

This is the result:

PanelBar With Menu

In this article