Link to home
Start Free TrialLog in
Avatar of npl77
npl77

asked on

Create A RadiobuttonList with Images Asp.net 2.0

I am populating a radiobuttonlist from my database. I would like to add images by each radiobutton populated. Can someone show me how to do this?
Avatar of guru_sami
guru_sami
Flag of United States of America image

How are you dataBinding your RBL?
Here is a link trying to do that:
http://aspdotnetcodebook.blogspot.com/2008/09/howto-display-radiobuttonlist-with.html

Other option is to use a DataBound Control like GV/Repeater and place a RadioButton and an Image Control.
Avatar of npl77
npl77

ASKER

Im not sure how to implement the example in the url. This is how I am populating the radiolist...

 if (!IsPostBack)
            {
                dt = BMHAccess.GetProducts();
                PopulateList(RadioButtonList1, dt);
               
            }
 
private void PopulateList(RadioButtonList list, DataTable products)
    {
        list.DataSource = products;
        list.DataTextField = "Name";
        list.DataValueField = "ProductId";
        list.DataBind();
 
    }

Open in new window

From where does the image come?
i.e. how do you get url to your image?
Avatar of npl77

ASKER

I have the images folder in my application. I dont know if I should store them somehow in my db or what
ASKER CERTIFIED SOLUTION
Avatar of guru_sami
guru_sami
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of npl77

ASKER

I cannot display the name? how can I display the name? I want it to look....
image "space" [ProductName]
Avatar of npl77

ASKER

ok I almost got it!
this displays correctly
 list.Items.Add(new ListItem(String.Format("<img src=\"{0}\">" +  " "+dt.Rows[i]["Name"].ToString(), imgsrc), value));

but now my string manipulation is wrong... because of this ("<img src=\"{0}\"> stuff can you help me fix this string manipulation to correspond witn what I got


        string sFormat = RadioButtonList1.SelectedItem.ToString();
        string[] nameprice;
        nameprice = sFormat.Split('-');
 
        btnTodaysSelections.ItemName = nameprice[0].TrimEnd();
        btnTodaysSelections.ItemNumber = RadioButtonList1.SelectedValue;
        btnTodaysSelections.Amount = decimal.Parse(nameprice[1].Substring(2));

Open in new window

Is the above code working?
Try like this ...
list.Items.Add(new ListItem(String.Format("<img src=\"{0}\">", imgsrc) + dt.Rows[i]["Name"].ToString(), value));
Avatar of npl77

ASKER

the data the SelectedItem is giving me is now...
<img src="images/AnImage1.gif"> Monthly Subscription - $29.95

I need string manipulation code to get rid of <img src="images/AnImage1.gif">
Avatar of npl77

ASKER

I got it thank you
oh i see what you mean:
try this:
     char[] ch = {'>','-'};
       string[] s1 = s.Split(ch);      
        string itemname = s1[1];
        string amount = s1[2];