Adding web user controls to RadPanelItem dynamically

2 posts, 0 answers
  1. Casey
    Casey avatar
    19 posts
    Member since:
    May 2011

    Posted 03 Feb 2012 Link to this post

    Does anyone have an example of how to dynamically add a web user control to a RadPanel? I have the following code, but it does not like how I am assigning the control. Does anyone have any ideas or a better way of doing this?
    Dim mainItem As New RadPanelItem()
    mainItem.Text = "Parent"
    mainItem.Expanded = True

    Dim secItem As New RadPanelItem()
    secItem.Text = "Child"
    secItem.Expanded = True

    Dim control As New RadPanelItem()
    Dim uc As Control = Page.LoadControl("~/WebUserControls/Panels/pnl_Selection.ascx")
    uc.ID = "ucSelection"
    control.Items.Add(uc)

    secItem.Items.Add(control)
    mainItem.Items.Add(secItem)
    pbPnlBar.Items.Add(mainItem)
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 06 Feb 2012 Link to this post

    Hello,

    Try the following code snippet.

    VB:
    Protected Sub Page_Load(sender As Object, e As EventArgs
        Dim dataitem1 As New RadPanelItem()
        dataitem1.Text = "Text"
        RadPanelBar1.Items.Add(dataitem1)
        Dim control As New RadPanelItem()
        Dim Panel1 As New Panel()
        Dim myControl As Control = LoadControl("~/WebUserControls/Panels/pnl_Selection.ascx")
        Panel1.Controls.Add(myControl)
        control.Controls.Add(Panel1)
        dataitem1.Items.Add(control)
    End Sub

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