Home > ASP.Net > Bind RadioButtonList to Image

Bind RadioButtonList to Image


try this example to Bind RadioButtonList to Image from folder in my website

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RadioListImage.aspx.cs" Inherits="RadioListImage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">
<html xmlns="<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>">
<head runat="server"> 
<title>Untitled Page</title>
<form id="form1" runat="server">     
<asp:RadioButtonList ID="rdoI" runat="Server">         

and in code behind :-

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class RadioListImage : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)  
string[] strImages = System.IO.Directory.GetFiles(Server.MapPath("~/img"));      
foreach (string strImage in strImages)      
this.rdoI.Items.Add(new ListItem(String.Format("<img src='{0}'>", strImage.ToString()), strImage.ToString()));      

Good Luck

Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: