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?
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();
}
From where does the image come?
i.e. how do you get url to your image?
i.e. how do you get url to your image?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I cannot display the name? how can I display the name? I want it to look....
image "space" [ProductName]
image "space" [ProductName]
ASKER
ok I almost got it!
this displays correctly
list.Items.Add(new ListItem(String.Format("<i mg src=\"{0}\">" + " "+dt.Rows[i]["Name"].ToStr ing(), 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
this displays correctly
list.Items.Add(new ListItem(String.Format("<i
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));
Is the above code working?
Try like this ...
list.Items.Add(new ListItem(String.Format("<i mg src=\"{0}\">", imgsrc) + dt.Rows[i]["Name"].ToStrin g(), value));
list.Items.Add(new ListItem(String.Format("<i
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">
<img src="images/AnImage1.gif">
I need string manipulation code to get rid of <img src="images/AnImage1.gif">
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];
try this:
char[] ch = {'>','-'};
string[] s1 = s.Split(ch);
string itemname = s1[1];
string amount = s1[2];
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.