More in this section

Forums / Developing with Sitefinity / List of "Today's" News

List of "Today's" News

3 posts, 0 answered
  1. Eric Wallace
    Eric Wallace avatar
    66 posts
    Registered:
    08 Oct 2009
    08 Jun 2010
    Link to this post
    Is there a way (FilterExpression?) to get a NewsView control to only list the articles that were published on the current day?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    08 Jun 2010
    Link to this post
    Hi Eric Wallace,

    You can use the FilterExpression property under the Advanced tab of the control, but you have to change the value manually every day. You should better create a custom control that inherits from NewsView and override CreateChildControls method where you add the following filter before calling the base

    ContentFilterBuilder filterBuilder = new ContentFilterBuilder(this);
    filterBuilder.ClearFilter();
    filterBuilder.AddFilter(new ContentFilterStatement("Publication_Date", DateTime.Now.Date.ToShortDateString(), ContentFilter.Condition.Equal));


    Best wishes,
    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. Eric Wallace
    Eric Wallace avatar
    66 posts
    Registered:
    08 Oct 2009
    08 Jun 2010
    Link to this post
    Thank you for your response Ivan. I did something similar in the meantime which is producing the desired result:

    NewsManager mgr = new NewsManager("News");
            List<IMetaSearchInfo> filters = new List<IMetaSearchInfo>();
     
            MetaSearchInfo filter = new MetaSearchInfo(MetaValueTypes.DateTime, "Publication_Date", DateTime.Today, SearchCondition.GreaterOrEqual);
            filters.Add(filter);
             
            filter = new MetaSearchInfo(MetaValueTypes.DateTime, "Publication_Date", DateTime.Today.AddDays(1), SearchCondition.LessThen);
            filters.Add(filter);
     
            news.DataSource = mgr.Content.GetContent(0, 10, "Publication_Date DESC", filters.ToArray()); ;
            news.DataBind();
Register for webinar
3 posts, 0 answered