This is a migrated thread and some comments may be shown as answers.

How to define childtemplate of a RadPanelBar bound to an ObjectDataSource

1 Answer 59 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Stephan asked on 06 Feb 2009, 04:34 PM
Hi, I have been trying to accomplice the following functionality with a RadPanelBar.

Version: 2008.3.1105.20

I have a panelbar which is bound to a datasource. I want to display the tekst of the returnitems as a panelItem. This is al working fine. For each item created I want to show a usercontrol. To get this working I defined the next code:

<telerik:RadPanelBar ID="rpbWizardStep2" runat="server" DataSourceID="odsPatterns" 
            DataValueField="PatternId" DataTextField="Pattern"  
            Width="100%" Skin="WebBlue" Height="100%" ExpandMode="FullExpandedItem" CollapseAnimation-Type="Linear" 
                <asp:Label ID="ParentKeyId" runat="server" Visible="True"></asp:Label> 
                <uc1:WizardItemControl runat="server" id="ucWizardItem" settype="MainGoal" EnableDateSelection="true" EnableDisciplineSelection="false" /> 
            <CollapseAnimation Type="Linear" Duration="100"></CollapseAnimation> 
            <ExpandAnimation Type="None" Duration="100"></ExpandAnimation> 
In my understanding this would render a panelbar whit textheaders, which would expand when clicked on. But instead the code renders a text RadPanelBar-item then the userControl and then again text and usercontrol. So the usercontrol is also threathed like a RadPanelBar-item at the highest level. (hope this is clear to someone).

In short what I want:

[ Tekst  1]
     [UserControl 1]
[ Tekst  2]
     [UserControl 1]
[ Tekst 3 ]
     [UserControl 1]

When clicked on one of the Tekst-items it should expland and show the content of the UserControl. As said, my code wil show the UserControl as one of the main-items (the same level as the Tekst-items)

Any ideas?

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 09 Feb 2009, 10:24 AM
Hi Stephan,

Please find below a sample code snippet that shows the needed approach.

<form id="form1" runat="server"
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
    <telerik:RadPanelBar ID="RadPanelBar1" runat="server" DataFieldID="id" DataFieldParentID="parentId" DataSourceID="SqlDataSource1" DataTextField="Text" OnItemDataBound="RadPanelBar1_ItemDataBound"
        <CollapseAnimation Duration="100" Type="None" /> 
        <ExpandAnimation Duration="100" Type="None" /> 
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Links]"></asp:SqlDataSource> 

using System; 
using System.Data; 
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) 
    protected void RadPanelBar1_ItemDataBound(object sender, Telerik.Web.UI.RadPanelBarEventArgs e) 
        RadPanelItem childItem = new RadPanelItem(); 
        Label lb = new Label(); 
        lb.Text = "You are in " + e.Item.Text + " item</br>"
        Control userControl = Page.LoadControl("~/WebUserControl.ascx"); 
        userControl.ID = e.Item.ID + "_userControl"

id  parentId    Text 
1   NULL        Politics 
2   NULL        CNN 
3   NULL        NBC 

Kind regards,
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question