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

Dynamic Binding to RadPanelBar Content Template

1 Answer 154 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nathan
Top achievements
Rank 1
Nathan asked on 26 Feb 2017, 10:31 PM

I am trying to bind to the Content Template of a RadPanelBar with and object (see below).  I am able to get the Panel Labels to display but the panel items are not expandable and they don't show the Rad Text Box inside the content. 

 

 

 <telerik:RadPanelBar  RenderMode="Lightweight" ID="RadPanelBar1" Runat="server"  Width="75%">
            <Items>
                <telerik:RadPanelItem runat="server">
                    <ContentTemplate>
                         <telerik:RadTextBox ID="RadTextBox1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "DetailMessage") %>'></telerik:RadTextBox>
                    
                    </ContentTemplate>
                </telerik:RadPanelItem>
            </Items>
            </telerik:RadPanelBar>

        public class DetailInfo
        {
            public string DetailMessage { get; set; }
        }
        public class PanelInfo
        {
            public int PanelId { get; set; }
            public string PanelLabel { get; set; }
            public DetailInfo Details { get; set; }
            public string DetailMessage {get; set; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            List<PanelInfo> PanelLabels = Enumerable.Range(1, 10).Select(m =>
                 new PanelInfo
                 {
                     PanelLabel = String.Format("Panel {0}", m),
                     PanelId = m,
                     Details = new DetailInfo { DetailMessage = string.Format("Detail {0}", m) },
                     DetailMessage = String.Format("Message {0}", m),
                 }
               ).ToList();

            RadPanelBar1.DataSource = PanelLabels;
            RadPanelBar1.DataTextField = "PanelLabel";
            RadPanelBar1.DataValueField = "PanelId";
            RadPanelBar1.DataBind();
          
        }

1 Answer, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 02 Mar 2017, 08:58 AM
Hello Nathan,

The ContentTemplate used in the provided code snippet is only for the specific item. Using the server-side binding provided in the code snippet creates new items which does not have ContentTemplate. 

In order to achieve setting the ContentTemplate for all items, one option is to use Server Templates and the OnTemplateNeeded event. 

Please find attached a sample project we prepared based on the provided code snippets.

Regards,
Peter Milchev
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
General Discussions
Asked by
Nathan
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Share this question
or