How to add Image to ASP.NET RadioButtonList

by Fighter18. July 2013 19:17

Below are the steps to create RadioButtonList with Images:
1. Create a folder in your solution and place all the images in it.
2. Create a foreach loop to loop through each items of the folder and create image tag.
3. Create a new ListItem and assign the image tag created in step 2.
4. Add this LsitItem to your RadiobuttonList.

Sample Code:

DirectoryInfo dir = new DirectoryInfo(Server.MapPath("Images//ReportImages"));
foreach (var file in dir.GetFiles())
{
     item = new ListItem("<img src='" + "Images/ReportImages/" + file.Name + "' alt='" + file.Name +
                                  "' title='" + file.Name + "'/>", Convert.ToString(i++));
      this.rptRadioListReport.Items.Add(item);
}

Like To Connect With US x