Telerik UI for ASP.NET AJAX

Using the server-side API, you can programmatically add, remove, and edit panel items.

Adding Items on page load

After simply adding a RadPanelBar control to your Web page, use the following server-side code to add items when the page loads:

Adding items dynamically

You can dynamically update the Items collection of RadPanelBar and RadPanelItem in response to a postback as well. Consider the following panel bar declaration:

CopyASPX
<telerik:RadPanelBar ID="RadPanelBar1" runat="server">
   <Items>
       <telerik:RadPanelItem runat="server" Text="Root Item1">
       </telerik:RadPanelItem>
       <telerik:RadPanelItem runat="server" Text="Root Item2">                  
       </telerik:RadPanelItem>               
   </Items>           
</telerik:RadPanelBar>
<asp:Button ID="Button1" runat="server" Text="Add Root Item" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Add Child Item" OnClick="Button2_Click"/>

A root item will be added upon a button click (Add Root Item button)A child item will be added to the first root item upon another button click (Add Child Items)

Clicking on both the buttons will result in the following:

PanelBar

Removing, disabling, and enabling items

To remove a panel item in server-side code, use the Remove method of the RadPanelItemCollection object that contains it. To enable or disable a panel item, use the Enabled property of the RadPanelItem object itself. The following example demonstrates these techniques:

Consider the following panel bar:

CopyASPX
<telerik:RadPanelBar ID="RadPanelBar1" runat="server">
   <Items>
       <telerik:RadPanelItem runat="server" Text="Root Item1" Expanded="true">
           <Items>
               <telerik:RadPanelItem runat="server" Text="Child Item"></telerik:RadPanelItem>
           </Items>
       </telerik:RadPanelItem>
       <telerik:RadPanelItem runat="server" Text="Root Item2">                  
       </telerik:RadPanelItem>               
   </Items>           
</telerik:RadPanelBar>
<asp:Button ID="Button1" runat="server" Text="Remove the Child Item" OnClick="Button1_Click" />

See Also