RadPanelBar - Collapse and Expand programmatically

3 posts, 0 answers
  1. Daniel
    Daniel avatar
    159 posts
    Member since:
    Feb 2014

    Posted 10 Mar 2014 Link to this post


    I am trying to add a RadPanelBar to my web project (ASP .NET AJAX).
    I want to do this programmatically (VB or C#).
    Inside each RadPanel item I want to place a RadGrid.

    I have two problems:

    1) I want to display three items of RadPanel items. I want the first item to show as expanded and the others as collapsed.

    2) I have a problem handling the event of clicking on an item and then expanding or collapsing the appropriate item.

    vb code:

    dim x as integer = 0
     Private Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        panel_SideMenu.ExpandMode = PanelBarExpandMode.SingleExpandedItem
    End Sub
     Private Sub setPanel(Of T)(ByVal list As List(Of T), ByRef ArrayNameFilds As Array, nameTitle As String)
            If Not IsPostBack Then
                Dim radGridTmp As New RadGrid
                radGridTmp.DataSource = list
                setColumnsOnGrid(radGridTmp, ArrayNameFilds)
                radGridTmp.ClientSettings.Selecting.AllowRowSelect = True
                radGridTmp.ClientSettings.EnablePostBackOnRowClick = False
                radGridTmp.ClientSettings.Scrolling.AllowScroll = True
                Dim radItemTmp As New RadPanelItem()
                radItemTmp.Text = nameTitle
                Dim radpanel As New RadPanelItem
                If x = 0 Then
                    radpanel.Expanded = True
                End If
                x += 1
            End If
       End Sub 


    <telerik:RadPanelBar ID="panel_SideMenu" Runat="server">

  2. Daniel
    Daniel avatar
    159 posts
    Member since:
    Feb 2014

    Posted 12 Mar 2014 in reply to Daniel Link to this post

    We found slightly different way to do it:
    First of all, we added in the ASPX: 

    <telerik:RadPanelBar ID="RadPanelBar1" runat="server" ExpandMode="SingleExpandedItem">
             <telerik:RadPanelItem runat="server" Text="t1" Value="t1">
                             <telerik:RadGrid ID="MyGrid1" runat="server">
             <telerik:RadPanelItem runat="server" Text="t2" Value="t2">
                     <telerik:RadGrid ID="MyGrid2" runat="server">
             <telerik:RadPanelItem runat="server" Text="t3" Value="t3">
                     <telerik:RadGrid ID="MyGrid3" runat="server">

    and Then we Add in the code: (VB.NET)

    Private Sub setpanel1(Of T)(list As List(Of T), grd_name As String, ArrayNameFilds As String(), val As String, name As String)
        If Not IsPostBack Then
            Dim panelItem As RadPanelItem = DirectCast(RadPanelBar1.FindItemByValue(val), RadPanelItem)
            Dim grid As RadGrid = DirectCast(panelItem.FindControl(grd_name), RadGrid)
            panelItem.Text = name
            grid.DataSource = list
            setColumnsOnGrid(grid, ArrayNameFilds)  'function that generate a grid
            grid.ClientSettings.Selecting.AllowRowSelect = True
            grid.ClientSettings.EnablePostBackOnRowClick = False
            grid.ClientSettings.Scrolling.AllowScroll = True
        End If
    End Sub
    on the page load, we call the function setPanel1 3 time:

    setpanel1(Of testObject)(listobj, grd_name:="MyGrid1", ArrayNameFilds:={"column1", "column2", "column3 -etc."}, val:="t1", name:="panel1")

  3. Nencho
    Nencho avatar
    1858 posts

    Posted 13 Mar 2014 Link to this post

    Hello Daniel,

    Thank you for contacting Telerik Support.

    I am glad to see that you were able to find an approach for achieving the desired functionality, by yourself.

    Please do not hesitate to contact us again, in case of further questions.


    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

Back to Top