0

I have a dropdownlist in my webform that contains several items (language select). I want to add a countryflag before the listitem text but asp.net doesn't render html in a dropdownlist. What is the best way to do so? The listitem value must be retained. The country flag is just an image...

I'm using a jquery attempt now but it doens't work.

ASP:

<asp:DropDownList
      id="ddlLanguage"
      runat="server"             
      DataTextField="Value"
      DataValueField="Text"
      AutoPostBack="true">
 </asp:DropDownList>

Code-behind:

ListItem langListEN = new ListItem("EN");
langListEN.Attributes.Add("id", "idEN");
ddlLanguage.Items.Add(langListEN);

jQuery

var flagEN = $('#ddlLanguage option#idEN');
flagEN.prepend( "<img src='../assets/images/country/gb.png' />" );
  • The basic `select` element doesn't support HTML. You'd need to either use a plugin or manually build a component which mimics the behavior of a `select` but is created using HTML elements. – David Nov 09 '17 at 13:16
  • try this http://www.c-sharpcorner.com/UploadFile/9f0ae2/Asp-Net-bind-dropdownlist-with-images/ –  Nov 09 '17 at 13:18

0 Answers0