Nesting RadListViews - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Nesting RadListViews

  • Nesting RadListViews
  • I want to list out all blog posts with all comments beneath them. I created a custom template, and I'm trying to use a RadListView repeater with a RadListView within it to display the comments for each post, but it's not working.

    If I try to use the comments insert
    <sitefinity:TextField runat="server" DisplayMode="Read" Value='<%# Eval("Comments")%>' />
    It simply displays

    Here's what I'm trying to display... there are a few custom fields, but it is a blog.

    <telerik:RadListView ID="Repeater" ItemPlaceholderID="ItemsContainer" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false">
        <div class="question">
          <h4><sitefinity:TextField runat="server" DisplayMode="Read" Value='<%# Eval("Asker")%>' /></h4>
          <sitefinity:HtmlField runat="server" DisplayMode="Read" Value='<%# Eval("Question")%>' WrapperTagName="p" />
           <div class="answer">
            <sitefinity:HtmlField runat="server" DisplayMode="Read" Value='<%# Eval("Answer")%>' WrapperTagName="p" />
            <p class="signature">- Laura</p>
           <div class="answer-cap"></div>
           <p class="qa-reply"></p>
      <telerik:RadListView ID="SingleItemContainer" ItemPlaceholderID="ItemContainer" AllowPaging="False" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false">
               runat="server" />
               runat="server" />
          <sitefinity:TextField runat="server" DisplayMode="Read" Value='<%# Eval("Comments")%>' />
          <div class="sfpostCommentsCount">
            <sf:CommentsBox ID="itemCommentsLink" runat="server"/>
  • Hi Adam,

    You have to subscribe for ItemDataBound event of the RadListView and from the dataitem you can get the comments for a given blog post, then display it.


    void SingleItemContainer_ItemCreated(object sender, RadListViewItemEventArgs e)
              // you should check for null values here. The first request returns null for the DataItem!
               var s = e.Item.OwnerListView.Items[0].DataItem as NewsItem;
               var c = s.Comments;
           void SingleItemContainer_ItemDataBound(object sender, RadListViewItemEventArgs e)
               foreach (var item in this.SingleItemContainer.Items)
                   var cntrl = item.FindControl("CommentsContainer") as RadListView;
                   if (item.ItemType == RadListViewItemType.DataItem || item.ItemType == RadListViewItemType.AlternatingItem)
                       var dataItem = item.DataItem as Telerik.Sitefinity.News.Model.NewsItem;
                       if (dataItem != null && cntrl != null)

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  • So do I have to create a custom control to do this?
  • Hello Adam,

    Yes it should be. The Comment is not property of the data that you are binding. You have Comments but this is IList<Comment>

    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  • Ok, so do I need to create a whole control that loops the blog posts and the comments beneath them? How do I pass the BlogID into the control from Sitefinity?

    I'm brand new to Sitefinity, so if you just want to link me to some instructions or something, that's cool.
  • Hi Adam,

    You have to use our API. Please take a look at Managing blogs

    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  • Hello,
    I want to Truncate Content upto 20 char.for that i have created my own Template in News=>List Settings as follows.

    <div id="divContent" runat="server"></div

    > over here i want to display my truncated Content ...






    is it right NewsList_OnItemDataBound() ?
    its giving me error for ; this ... Can you please suggest me something ... Thanks ...

    <%@  Control Language="C#" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.ContentUI" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.Comments" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI.PublicControls.BrowseAndEdit"
        Assembly="Telerik.Sitefinity" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="samples" Namespace="Telerik.Sitefinity.Samples" Assembly="Communicate2" %>
    <link href="../../include/css/master.css" rel="stylesheet" type="text/css" />
    <script runat="server">      
        protected void NewsList_OnItemDataBound(object sender, RadListViewItemEventArgs e)
            if (e.Item is RadListViewDataItem)
                RadListViewDataItem item = e.Item as RadListViewDataItem;
                string Content = (item.DataItem as Telerik.Sitefinity.News.Model.NewsItem).Content;

                HtmlGenericControl divContent = e.Item.FindControl("divContent") as HtmlGenericControl;
                if (divContent != null)
                    divContent.InnerHtml = Content.Substring(0, 20);

    <div class="newsList">
        <telerik:RadListView ID="NewsList" ItemPlaceholderID="ItemsContainer" runat="server"
            EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false" OnItemDataBound="NewsList_OnItemDataBound">
                <sf:ContentBrowseAndEditToolbar ID="MainBrowseAndEditToolbar" runat="server" Mode="Add">
                <ul class="sfnewsList sfnewsListTitleDateSummary">
                    <asp:placeholder id="ItemsContainer" runat="server" />
                <li class="sfnewsListItem">
                    <div class="sfImg">
                        <samples:SimpleImageField ID="SimpleImageField1" runat="server" DisplayMode="Read"
                            Value='<%# Eval("ThumbnailURL")%>' />
                    <h2 class="sfnewsTitle">
                            <sf:DetailsViewHyperLink ID="DetailsViewHyperLink1" TextDataField="Title" ToolTipDataField="Description"
                                runat="server" />
                    <div class="sfnewsMetaInfo">
                        <sf:FieldListView ID="PostDate" runat="server" Format=" PublicationDate.ToLocal():MMM dd, yyyy" />
                    <div class="sfnewsComment">
                        <sf:CommentsBox ID="itemCommentsLink" runat="server" CssClass="sfnewsCommentsCount" />
                    <a class="sfnewsFullStory">
                        <%--<sitefinity:HtmlField ID="HtmlField1" runat="server" DisplayMode="Read" Value='<%# Eval("Content")%>' />--%>
                        <div id="divContent" runat="server">
                    <sf:ContentBrowseAndEditToolbar ID="BrowseAndEditToolbar" runat="server" Mode="Edit,Delete,Unpublish">
    <sf:Pager ID="pager" runat="server">


  • Hello A,

    Try using ItemDataBound event of the RadListView.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
  • Hi Ivan Dimitrov ,
                               I have same problem with my code. I have used same code as above, but getting 'Error parsing the template' error. please let me give solution with sample.

    Thanks & regards,
    Pravat Sharma
  • Hi Pravat,

    I suggest that  you should take up to date template from our SDK. It looks like this one is obsolete, since it is for 4.0  BETA release.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>