More in this section

Forums / Developing with Sitefinity / Record Count on News, Events (etc.) View Control Template

Record Count on News, Events (etc.) View Control Template

4 posts, 0 answered
  1. John Dentler
    John Dentler avatar
    12 posts
    Registered:
    23 Apr 2010
    15 May 2010
    Link to this post
    Hi Guys,

    What's the best way to get the total record count for the repeater on the news view, events view, download list, etc control templates?

    I'm looking for something simple, like it is for the Search Results control template:

     <asp:Literal ID="ResultsStats" runat="server">{0}</asp:Literal> results found

    I've seen this post but it's not really straight forward, and I have no idea what "FindParentContentView" is in the code provided.

    I'm guessing there's any easy way because the pagers on the news, events, etc custom templates are based on the total records by some query some where.

    Thanks for any help!

    John D

     

     

     

     

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    15 May 2010
    Link to this post
    Hi John Dentler,

    The best way is to get count of the datasource items of the ContentView based control. You should create a custom control that inherits from NewsView ( or BlogPosts, EventsView etc) and override CreateDataSource method. You could persist the value to a ViewState property and then set the value as a Text of a Label/Literal or another control.

    protected override System.Collections.IList CreateDataSource()
      {
          int l = base.CreateDataSource().Count;
     
          return base.CreateDataSource();
          
     
      }


    Greetings,
    Ivan Dimitrov
    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.
  3. John Dentler
    John Dentler avatar
    12 posts
    Registered:
    23 Apr 2010
    15 May 2010
    Link to this post
    Hi Ivan,

    Thanks for the response. Would you please attach or provide an example? I'm just not able to get anything working.
    I did try:
    base.CreateDataSource().Count;

    ...but that only gave me the repeater count per page, not a total datasource count.

    Regardless, I absolutely don't understand how to pass anything from CustomNewsView, which inherits NewsView, to the control template ( ie. ListPageMaster.ascx ). I can't get ViewState to work, "TotalRecords" doesn't exist and nothing is displayed.

    I really don't want to have to use User Controls and the API to get this done; I'd like to stick with sitefinity control templates, but I may have to as I'm simply running out of time. The only other option is to tell the client that they won't get the TOTAL number of items for the list control, which is such a common feature.

    Why did you guys not pass that value thru to the template like you do for Search Results?

    Thanks for any help!

    John D

     

    namespace CCC.Sitefinity.Modules.WebControls
    {
        public class CustomNewsView : NewsView
        {
            protected override IList CreateDataSource()
            {
                TotalRecords = base.Manager.ContentCount().ToString();
      
                return base.CreateDataSource(); 
            }
      
            public string TotalRecords
            {
                get
                {
                    string s = ViewState["TotalRecords"] as string;
                    return (s == null) ? string.Empty : s;
                }
                set
                {
                    ViewState["TotalRecords"] = value;
                }
            }
        }
    }

     

     

    <table class="pager" border="0" cellpadding="2" cellspacing="0" width="100%" summary="">
        <tbody>
            <tr>
                <td align="left" valign="bottom">
                    <span><%= ViewState["TotalRecords"].ToString() %> news items found</span>
                </td>
                <td align="right">
                    <telerik:Pager ID="pager1" runat="server">
                        <LayoutTemplate>

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    16 May 2010
    Link to this post
    Hi John Dentler,

    Override CreateChildControls as shown below and get a list of all items.

    protected override void CreateChildControls()
        {
            base.CreateChildControls();
            ContentFilterBuilder filterBuilder = new ContentFilterBuilder(this);
            if (filterBuilder.IsFilterValid)
            {
                var list = this.manager.GetContent(0, 0, this.SortExpression,
                                            filterBuilder.ParseTagFilter(), ContentStatus.Published, null,
                                            filterBuilder.ParseParentsFilter(), filterBuilder.ParseMetaFieldsFilter());
            }
        }

    By default the datasource is created depending on the pager due to performance optimizations, so if you have 50 pages we load only the items that are displayed by the current page - say 10 items.

    All the best,
    Ivan Dimitrov
    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.
Register for webinar
4 posts, 0 answered