In code behind I am creating a Control : a dropdownlist with inside some pictures.
DropDownList ddlEventIcone = new DropDownList();
ddlEventIcone.ID = "eventIconeDDL";
ddlEventIcone.Width = Unit.Pixel(110);
Then I want to put picutures inside, so I get them from a map created like so :
Dictionary<string, Image> iconeMapping = new Dictionary<string, Image>();
iconeMapping .Add(iconeName, myImage);
I put them in a ListItem which I'll bind to the dropdownlist:
foreach (Image image in iconeMapping.Values.ToArray())
{
lImageddl.Add(image.ImageUrl.Replace("~", "../.."));// the tild wasn't working
}
I bind my list with the dropdownList :
ddlEventIcone .DataSource = lImageddl;
ddlEventIcone .DataBind();
I use Javascript to precise the 'type' of the element as Img:
foreach (ListItem listItem in ddlEventIcone.Items.Cast<ListItem>())
{
listItem.Attributes.Add("class", "imageconverter");
}
With the Javascript :
$(function () {
$(".imageconverter").each(function () {
$(this).html('<img src="' + $(this).text() + '">');
});
});
The Result is a dropdownlist with 'empty' options, nothing is shown (blank rows) BUT in the source page here is what I've got :
<select name="DigitalCalendarGrid$ctl09$eventIconeDDL" id="DigitalCalendarGrid_ctl09_eventIconeDDL" style="width:110px;">
<option value="../../images/Event/cycling.png" class="imageconverter" width="10" height="10"><img src="../../images/Event/cycling.png"></option>
<option value="../../images/Event/football.png" class="imageconverter" width="10" height="10"><img src="../../images/Event/football.png"></option>
</select>
EDIT Precision : in the Chrome DevTools when I pass the mouse on the picture path it shows the picture but it says
0x0 pixels (Natural 256x256 pixels)