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

Databound PanelBar with ContentTemplates?

4 Answers 176 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 15 Jul 2010, 08:16 PM
Hello,

I am trying to databind a RadPanelBar (2010 Q2 release) to achieve a specific behavior, and I am having trouble getting it to work.

If I have the panelbar in my aspx like so:

<telerik:RadPanelBar ID="rpbRel" runat="server" OnItemDataBound="rpbRel_ItemDataBound" >
    <ItemTemplate>
        <div class="DestinationWrapperBox">
            <asp:TextBox runat="server" id="txtRel" />
        </div>
    </ItemTemplate>
</telerik:RadPanelBar>

And code-behind like so:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim colTypes As System.Collections.ObjectModel.Collection(Of RelationshipType)
 
    rpbRel.DataSource = colTypes
    rpbRel.DataTextField = "Name"
    rpbRel.DataValueField = "ID"
    rpbRel.DataBind()
End Sub
 
Protected Sub rpbRelationships_ItemDataBound(ByVal sender As Object, ByVal  e As Telerik.Web.UI.RadPanelBarEventArgs)
    Dim oRelType As RelationshipType
    Dim txtTemp As TextBox
  
    oRelType = CType(e.Item.DataItem, RelationshipType)
  
    txtTemp = CType(e.Item.FindControl("txtRel"), TextBox)
    If Not IsNothing(txtTemp) Then
        txtTemp.Text = oRelType.Name
    End If
End Sub

Then what I get is a PanelBar that works correctly, but the items are not collapsible.  I have read in various places that I should add RadPanelItem and add a ContentTemplate and put my template there.

If I move the aspx template code, like so:
<telerik:RadPanelBar ID="rpbRel" runat="server" OnItemDataBound="rpbRel_ItemDataBound" >
    <Items>
        <telerik:RadPanelItem runat="server">
            <ContentTemplate>
                <div class="DestinationWrapperBox">
                    <asp:TextBox runat="server" id="txtRel" />
                </div>
            </ContentTemplate>
        </telerik:RadPanelItem>
    </Items>
</telerik:RadPanelBar>

And leave my codebehind the same, then I get collapsed elements that won't expand.

I have traced into the databound procedure under this second scenario, and when it binds e.item is a RadPanelBarItem that has no child items or controls, so the e.item.findcontrol("txtRel") returns nothing.

I feel like I must be binding something wrong somewhere, but I am not sure how to accomplish what I want.

Ideally, I will get PanelBarItems that have their text set to "Name", and have a textbox "under" them, that can be shown or hidden by clicking on the panelbar.  The first example gets me everything except the ability to collapse them.

Is it possible to do what I want?

Josh

4 Answers, 1 is accepted

Sort by
0
Nikolay Tsenkov
Telerik team
answered on 16 Jul 2010, 02:46 PM
Hi Josh,

The problem here is that the ContentTemplate is per Item - it's not for all items. That's why the only way to achieve the requirement you have will be to:
1. Create a Class in the code-behind of the page implementing ITemplate interface, which will represent the content template that you want (here is a link for the reference about dynamic templating: http://www.telerik.com/help/aspnet-ajax/panel_add-templates-runtime.html);
2. Trap the TemplateNeeded server-side event and apply the template over the currently created item (it's raised for every single item created from the dataSource).

This way, you will still bind the panelBar and you will be able to use the benefit of ContentTemplate (to collapse the template of a single item that doesn't have any children).

Hope this is going to help you!


Regards,
Nikolay Tsenkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Karl
Top achievements
Rank 1
answered on 03 Dec 2010, 04:40 PM
I'm having this issue too (dynamically adding panel items to a panelBar and dynamically adding a radgrid to each of these panel items) but am also unable to add the controls and have the panel items collapsible.

I can add the panel items to the panelbar, and -for testing - can add a label as a control to each panel item, but the panels wont collapse. even the expand/collapse images which I have placed oon the left of the panel items have disappeared..

I followed your example ( http://www.telerik.com/help/aspnet-ajax/panel_add-templates-runtime.html)
of how to dynamically add ItemTemplates, but this doesn't explain how to add HeaderTemplate or ContentTemplate items even though it says they are done in the same manner. These templates do not appear in the object model of the panelbar, only the ItemTemplate does.

I've added an image to show what my panel looks like right now... the red question marks are where my expan/collapse images should be...
0
Karl
Top achievements
Rank 1
answered on 03 Dec 2010, 05:01 PM
looks like my image didnt attached so trying again...

0
Nikolay Tsenkov
Telerik team
answered on 08 Dec 2010, 02:54 PM
Hi Karl,

Could you, please, open a support ticket, send us a sample project (or post the code here) and explain in a bit more detail what exactly do you try to achieve and what seems to be the problem doing so?
Thanks!


Regards,
Nikolay Tsenkov
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
PanelBar
Asked by
Josh
Top achievements
Rank 1
Answers by
Nikolay Tsenkov
Telerik team
Karl
Top achievements
Rank 1
Share this question
or