+1-888-365-2779
Try Now
More in this section

Forums / Sitefinity SDK / Nesting RadListViews

Nesting RadListViews

10 posts, 0 answered
  1. Adam
    Adam avatar
    3 posts
    Registered:
    02 Feb 2011
    03 Feb 2011
    Link to this post
    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
    Telerik.Sitefinity.Model.ProviderTrackedList`1[Telerik.Sitefinity.GenericContent.Model.Comment]

    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">
      <ItemTemplate>
        <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>
            
           <div class="answer-cap"></div>
           <p class="qa-reply"></p>
        </div>
         
      <telerik:RadListView ID="SingleItemContainer" ItemPlaceholderID="ItemContainer" AllowPaging="False" runat="server" EnableEmbeddedSkins="false" EnableEmbeddedBaseStylesheet="false">
        <ItemTemplate>
          <sf:ContentView
               id="commentsListView"
               ControlDefinitionName="BlogsCommentsFrontend"
               DetailViewName="CommentsMasterView"
               ContentViewDisplayMode="Master"
               runat="server" />
          <sf:ContentView
               id="commentsDetailsView"
               ControlDefinitionName="BlogsCommentsFrontend"
               DetailViewName="CommentsDetailsView"
               ContentViewDisplayMode="Detail"
               runat="server" />
          <sitefinity:TextField runat="server" DisplayMode="Read" Value='<%# Eval("Comments")%>' />
     
          <div class="sfpostCommentsCount">
            <sf:CommentsBox ID="itemCommentsLink" runat="server"/>
          </div>
         </ItemTemplate>
        </telerik:RadListView>
      </ItemTemplate>
    </telerik:RadListView>
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    04 Feb 2011
    Link to this post
    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.

    sample

    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.
  3. Adam
    Adam avatar
    3 posts
    Registered:
    02 Feb 2011
    04 Feb 2011
    Link to this post
    So do I have to create a custom control to do this?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    04 Feb 2011
    Link to this post
    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>

    Regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Adam
    Adam avatar
    3 posts
    Registered:
    02 Feb 2011
    04 Feb 2011
    Link to this post
    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.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    04 Feb 2011
    Link to this post
    Hi Adam,

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

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Anu
    Anu avatar
    72 posts
    Registered:
    17 Jun 2010
    21 Apr 2011
    Link to this post

    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);

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

     

  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    21 Apr 2011
    Link to this post
    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 >>

  9. Pravat
    Pravat avatar
    59 posts
    Registered:
    22 Jun 2010
    14 Nov 2011
    Link to this post
    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
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    19 Sep 2016
    15 Nov 2011
    Link to this post
    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 >>

10 posts, 0 answered