How to define childtemplate of a RadPanelBar bound to an ObjectDataSource

2 posts, 1 answers
  1. Stephan
    Stephan avatar
    71 posts
    Member since:
    Jul 2007

    Posted 06 Feb 2009 Link to this post

    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" 
                OnPreRender="rpbWizardStep2_PreRender"
                <ItemTemplate> 
                    <asp:Label ID="ParentKeyId" runat="server" Visible="True"></asp:Label> 
                    <uc1:WizardItemControl runat="server" id="ucWizardItem" settype="MainGoal" EnableDateSelection="true" EnableDisciplineSelection="false" /> 
                </ItemTemplate> 
                <CollapseAnimation Type="Linear" Duration="100"></CollapseAnimation> 
                <ExpandAnimation Type="None" Duration="100"></ExpandAnimation> 
            </telerik:RadPanelBar> 
    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?






  2. Answer
    Paul
    Admin
    Paul avatar
    4281 posts

    Posted 09 Feb 2009 Link to this post

    Hi Stephan,

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

    ASPX:
    <form id="form1" runat="server"
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"
        </telerik:RadScriptManager> 
        <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" /> 
        </telerik:RadPanelBar> 
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Links]"></asp:SqlDataSource> 
    </form> 

    Code-behind:
    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(); 
            e.Item.Items.Add(childItem); 
     
            Label lb = new Label(); 
            lb.Text = "You are in " + e.Item.Text + " item</br>"
            childItem.Controls.Add(lb); 
     
            Control userControl = Page.LoadControl("~/WebUserControl.ascx"); 
            userControl.ID = e.Item.ID + "_userControl"
            childItem.Controls.Add(userControl); 
        } 
     

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


    Kind regards,
    Paul
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top