More in this section

Forums / Developing with Sitefinity / How to bind content to any control property

How to bind content to any control property

2 posts, 1 answered
  1. Cristian Grisolia
    Cristian Grisolia avatar
    6 posts
    Registered:
    04 Sep 2009
    04 Sep 2009
    Link to this post
    Hi everyone,
    I need to implement a very simple products list view and I'm using your Product module (sample implementation of generic content). My intention is to modify the ContentViewItemList.ascx template. I've added a thumbnail metafield to the products module in order to display this image on the list. The first obstacule I'm facing is how to bind this new metafield content to the ImageUrl property of an ImageControl (since for what I understand, controls in templates binds only its Text property). What is the best approach for binding content with other controls properties?

    Thanks in advance
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    06 Sep 2009
    Link to this post
    Hello Cristian Grisolia,

    By default if you add an Image control and sent the same ID as your metakey the image url will be automatically set.

    Metakey

    <add key="News.MyThumbnail" valueType="ShortText" visible="True" searchable="False" sortable="False" defaultValue=""/> 

    Image control in your template

    <asp:Image ID="MyThumbnail" runat="server" /> 

    Another option is using DataBinder.Eval()

    <asp:Image ID="test1" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "NewThumbnail").ToString() %>' /> 


    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
2 posts, 1 answered