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

Forums / Developing with Sitefinity / No way to set item ID for ContentView?

No way to set item ID for ContentView?

4 posts, 0 answered
  1. Schneider
    Schneider avatar
    29 posts
    Registered:
    02 Nov 2008
    02 Mar 2009
    Link to this post
    I am looking at the ContentView source code and it appears there is no way to set the content ID for a single item to display.

    Seems like a rather massive oversight?

    If I use the FilterExpression (which I assume is the 'best practice' considering most of the other properties are now marked as obsolete) and use ID = 'some guid' it does not work.

    I can see why in the source code.
    - Unless itemId is set then the single item template is not used.
    - The only way to set itemId is to give a value in Context.Items or Context.Request for the ContentItemKey.
    - Neither of those values can be set from the page designer in SF afaik

    So how do I tell it what single item to display without using the obsolete fields? (SelectItemId works but its obsolete apparently....)
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    02 Mar 2009
    Link to this post
    Hello Schneider,

    Here is a way to get the content item by passing the id.

    ContentManager contentManager = new ContentManager("News"); 
    Guid id = new Guid("49fbc8c0-2e25-4c6d-9555-b7b6fa85bac7"); 
    IContent content = contentManager.GetContent(id); 
    Response.Write(content.Content); 

    Using FilterExpression you can filter content items that will be shown by provider's metafields. For instance, if you have meta key "Title" you could get the item by "Title"
     Example:

    Publication_Date <= "#now" AND Expiration_Date > "#now" AND Title = "MyTitle" 

    I hope this helps.

    Greetings,
    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.
  3. Schneider
    Schneider avatar
    29 posts
    Registered:
    02 Nov 2008
    02 Mar 2009
    Link to this post
    I think you have misunderstood my question.

    I know how to get the content item from a guid using a content manager.

    My question was: How do I configure a ContentView to show a single content item of a specific ID?

    e.g. Why can't I used FilterExpression: ID = '000-0000-000-0000-00000' with ContentView?

    Of course I can do it by setting the SelectedItemId... but according to Sitefinity that property is obsolete.

    If it is obsolete where is the equivalent function that is not obsolete?

    Seems very broken to me if you can't do this without using an 'obsolete' property.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    03 Mar 2009
    Link to this post
    Hello Schneider,

    Please use SelectedItemId. It is working although it is under obsolete member section. We have added this sections due to the changes that we will make for 4.0 when we are going to have a new API for GenericContent.

    Greetings,
    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
4 posts, 0 answered