Search code examples
asp.netimagedata-bindingradiobuttonlist

ASP.Net add image to radiobuttonlist items on load


I have a RadioButtonList that is bound to a datatable. Within the datatable, a column exist with urls of images and another column with the description.

The following is what I am doing right now (not working though):

     foreach ( acryliccolor scurrent in ssmacryliccolor )
     {
        DataRow dr = dt.NewRow();
        dr["TEXT"] = "<img src=\"\\colorswatches\\" + scurrent.SwatchURL + "\" alt=\"\" border=\"0\" /><span style=\"margin-right:21px;\"></span>"  + scurrent.Color;
        dr["VALUE"] = "ID|SC_" + scurrent.ID.ToString() + ";CSID|" + current.ID.ToString() + ";JS|radiosimple(this)";
        dt.Rows.Add(dr);
     }
     this.rblAcrylicColors.DataSource = dt;
     this.rblAcrylicColors.DataTextField = "TEXT";
     this.rblAcrylicColors.DataValueField = "VALUE";
     this.rblAcrylicColors.DataBind();

How do I add the image next to the description for each radiobutton item?


Solution

  • Have you tried dynamically adding items to the radiobuttonlist.Items collection?

    this.rblAcrylicColors.Items.Add(String.Format("<img src={0} />", "url"));
    

    Also have you checked the html output from what you are currently trying? Is the img tag there?