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

Forums / Developing with Sitefinity / Show only this year's date in NewsView

Show only this year's date in NewsView

7 posts, 0 answered
  1. James@Nw
    James@Nw avatar
    265 posts
    Registered:
    05 May 2009
    18 Jun 2009
    Link to this post
    Hi Guys,

    We need to show the current year's news in the NewsView when you click on the News section of our site. From there we have an archive of previous years of news articles which will then show when clicked on. Could you please let me know how I can do this?

    Thanks!

    Cheers,
    James
  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    18 Jun 2009
    Link to this post
    Hello James,

    Please follow these steps:
    1. Enter into the backend
    2. Edit the page in which you have the NewsView control
    3. Edit the NewsView control and go to Advanced tab -> Filters section
    4. Set the following value for the FilterExpression property:
    • Publication_Date >= "01/01/2009"
    This should force the NewsView control to list news with publication date set to 01/01/2009 or later. (The data format is MM/DD/YYYY).
    5. Save the changes and the page.

    This should do the trick.

    Sincerely yours,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. James@Nw
    James@Nw avatar
    265 posts
    Registered:
    05 May 2009
    18 Jun 2009
    Link to this post
    Thanks Georgi that's great and it will work for this year!

    Is there no way that I can set it for the current year? So in 2010 it should read all the articles of that year?

    Thanks,
    James
  4. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    18 Jun 2009
    Link to this post
    Hi James,

    This is not possible with the built in control, but there is a way for you to do this with a user control or custom control containing the NewsView control. Here is how - I will do it with a User Control:

    1. Create a user control.
    2. In the Page_Load event add the following code:
        protected void Page_Load(object sender, EventArgs e) 
        { 
            NewsView newsViewControl = new NewsView(); 
            DateTime date = DateTime.Now; 
     
            newsViewControl.FilterExpression = "Publication_Date >= 01/01/" + date.Year; 
            this.Controls.Add(newsViewControl); 
        } 

    3. Upload the user control through the user interface in Toolbox controls.

    The whole example is attached to this thread.

    Please note that you will not be able to edit the NewsView control properties, since if you click on Edit button, you will edit the User Control properties. This will not be the case if we had created a Custom Control. I can show you this approach tomorrow though, if you need it.

    Regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Simon
    Simon avatar
    28 posts
    Registered:
    27 Jun 2008
    25 Jun 2009
    Link to this post
    Hi Georgi,

    I would like to see how to create such a control. I have an identical requirement, I need the "News" page to display items for the current year and an archive page to display articles for previous years. I noticed that the filter expressions allow keywords like #now but don't recognise Now.Year

  6. James@Nw
    James@Nw avatar
    265 posts
    Registered:
    05 May 2009
    26 Jun 2009
    Link to this post
    Hi Georgi.

    Thanks for the code and the example you sent through, I appreciate it!

    With the default control in Sitefinity; we don't quite understand the way this control works. 

    If I check the filter it says:
    Publication_Date <= "#now" AND Expiration_Date > "#now"

    Our news archive pulls out a bunch of random dates and displays that for the first time which I would assume comes from the AND Expiration_Date > "#now"?

    Your solution worked but it now only works if you are on the current year in this case 2009. If I now click on any previous year (back to 2003) these archives don't show at all.

    Can you help with this?

    Thanks again.
    James
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    26 Jun 2009
    Link to this post
    Hi James,

    You can use FilterExporession like :

    Publication_Date > "01-01-2008" AND Expiration_Date < "01-01-2009" 

    This will show the items between 1st of January 2008 and 1st of January 2009. As you see you can specify all dates you want.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
7 posts, 0 answered