I have a sitecore control like this: <sc:Image ID="imgLogo" runat="server" Field="Image"/>
Now the current item does not have an Image field. I am pulling the Item through droptree in CurrentItem like this (GetFieldValue is same as GetField. I am overriding the base class in Sitecore):
string countryGuid = CurrentItem.GetFieldValue("Country", null);
Item country = sitecoreDatabase.GetItem(countryGuid);
BindCountryLogo();
Now in this Item I have an image for the country logo. All I want to show up on the sc:Image.
So far I got this:
private void BindCountryLogo(Item country)
{
Fields.ImageField logoField = country.Fields["Image"];
if (logoField != null && logoField.MediaItem != null)
{
//Sitecore.Data.Items.MediaItem image = new MediaItem(logoField.MediaItem);
//string src = Sitecore.Resources.Media.MediaManager.GetMediaUrl(image);
//imgLogo.DataSource = src;
//imgLogo.ImageUrl = logoField.MediaItem.Source.;
//string src = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(logoField));
//Sitecore.Data.Items.MediaItem img = new MediaItem(ImageField.Medi)
}
}
None of them are working.
The control has a property “Item” which you can set to the item that holds the imageField.
Your BindCountryLogo should look like this:
(Or remove the BindCountryLogo() method and set the Item in the main method 😉 )