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

Forums / Developing with Sitefinity / repeaterItemMetaData ??

repeaterItemMetaData ??

5 posts, 1 answered
  1. Andrew
    Andrew avatar
    202 posts
    Registered:
    05 Jun 2009
    16 Jul 2009
    Link to this post

    I have been working with the products module sample. Creating a module based on it.
    I am somewhat stuck.

    I have created a metadata item, an image. Similar to the news module that has a thumbnail.

    I would like to be able to display the image in the preview view. However right now it simply displays the list of all metadata items.

    Using this code:

    <asp:Repeater ID="repeaterItemMetaData" runat="server">  
                            <ItemTemplate> 
                                    <dt> 
                                        <asp:Literal ID="lblKey" runat="server" /> 
                                    </dt> 
                                    <dd> 
                                        <asp:Literal ID="lblValue" runat="server" /> 
                                    </dd> 
                            </ItemTemplate> 
                            </asp:Repeater> 

    How can i access the matadata items without the repeater. I would like to load the image into the background of a table. So that it apears as a backgroud in the preview.

    And while we at it how can i get the html from my content without the "<telerik:GenericContent ID="contentPreview" runat="server" />"



  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    16 Jul 2009
    Link to this post
    Hello Andrew,

    The repeater is a data-bound list control that allows custom layout by repeating a specified template for each item displayed in the list. The methods behind the repeater are responsible for showing the metadata. Generally you have content item and you call GetMetaData() method. You can get the content from a generic content item even using a literal control ( it will be a plain text) by setting the Literal.Text to equals contentItem.Content.

    All the best,
    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. Andrew
    Andrew avatar
    202 posts
    Registered:
    05 Jun 2009
    17 Jul 2009
    Link to this post

    Hi Ivan,

    This is the code I am using right now:

     

     

     

     

                ContentManager manager = new ContentManager("Barkers");  
                IContent content = manager.GetContent(this.ContentPreview.ContentID);  
     
                //Text  
                ((Label)ContentLabel).Text = content.Content.ToString();  
     
                //Image  
                string imageURL = content.GetMetaData("Image").ToString();  
     
                string[] keys = imageURL.Split(']');  
                string providerName = keys[0].Replace("[", String.Empty);  
                Guid itemId = new Guid(keys[1]);  
     
                LibraryManager libManager = new LibraryManager(providerName);  
                IContent item = libManager.GetContent(itemId);  
     
                ((Table)MainTable).BackImageUrl = item.UrlWithExtension; 

     

     


    It works just fine. For the most part.
    What i am not entirely happy with is this:

     

     

     

     

    ContentManager manager = new ContentManager("Barkers");  
    IContent content = manager.GetContent(this.ContentPreview.ContentID); 

    Since i am in a control that inherits from contentpreview, i was hoping i would be able to access the actual content somehow from base. Maybe like this: base.Content, but i can't see it.

    Doing it the way i did it seems a bit of an overkill. It's like i am retrieving data that i should already have.

     

    What do you think, is there a better way to do this?

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    17 Jul 2009
    Link to this post
    Hi Andrew,

    There is so method in ConntentItemPreview that returns contentItem as a parameter. You should call the Manager and pass the id of the content

    var cnt = this.Manager.GetContent(itemId);

    Sincerely yours,
    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.
    Answered
  5. Andrew
    Andrew avatar
    202 posts
    Registered:
    05 Jun 2009
    17 Jul 2009
    Link to this post
    Thanks.
    Exactly what i was looking for.
Register for webinar
5 posts, 1 answered