I am attempting to create a radiobuttonlist as a result of value retrieved from the db. In the db i have a name of picture file in which i will return. I want the radiobuttons to interpret this value and populate an image. I am currently doing this with an
image displaying in a datagrid but not for a radiobutton. Here is what i have, but it will not retrieve the image? <img src='/pic_directory_here/
1) Your image tag is not complete. It should be: (quote and closing tag at the end) 2) Did you look at (can you show us part of) the html generated when the page is rendered?
3) Can you show us your databind() code for the radiobuttonlist? 4) Try this to see if there is a problem with your fixpicture method. -ron
Ron, I tried this and it still will not find my images. Here is what the HTML translated to: <img src='/peifootball/gifs/<%# Container.DataItem("team_pic") %>' > How does the databinding work with the radiobutton list? I am only databinding the datalist.
I am not sure if this is what you want but this is what is generated. I am just not sure if radiobuttons can be generated from a file name retrieved from the database. It will work if i hard
code the name of the file into the img src but not when i bring in the db value.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
GenImage()
End If
End Sub
Sub GenImage()
Dim a As ArrayList = New ArrayList
a.Add("bl.gif")
a.Add("bc.gif")
a.Add("cc.gif")
For Each s As String In a
RadioButtonList1.Items.Add(New ListItem("", s))
Next
End Sub
morgation
Member
15 Points
3 Posts
Radiobuttonlist Image Setting
Oct 02, 2003 03:56 PM|LINK
macha27
Member
750 Points
148 Posts
Re: Radiobuttonlist Image Setting
Oct 02, 2003 06:39 PM|LINK
morgation
Member
15 Points
3 Posts
Re: Radiobuttonlist Image Setting
Oct 06, 2003 06:09 PM|LINK
macha27
Member
750 Points
148 Posts
Re: Radiobuttonlist Image Setting
Oct 07, 2003 01:03 AM|LINK
morgation
Member
15 Points
3 Posts
Re: Radiobuttonlist Image Setting
Oct 07, 2003 01:11 PM|LINK
macha27
Member
750 Points
148 Posts
Re: Radiobuttonlist Image Setting
Oct 07, 2003 02:23 PM|LINK
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then GenImage() End If End Sub Sub GenImage() Dim a As ArrayList = New ArrayList a.Add("bl.gif") a.Add("bc.gif") a.Add("cc.gif") For Each s As String In a RadioButtonList1.Items.Add(New ListItem("", s)) Next End Suband this on the html page -rongreatbear
Member
153 Points
137 Posts
Re: Radiobuttonlist Image Setting
Jul 22, 2008 02:28 PM|LINK
The ListItem tag should contain a "value" attribute for the image to appear. ;)
rashmi.t.aga...
Member
2 Points
1 Post
Re: Radiobuttonlist Image Setting
Oct 23, 2008 07:34 PM|LINK
Hi, I am facing the same problem.
Following is my aspx code :
<
tr><td >asp:RadioButtonList ID="rlCards" runat="server"></asp:RadioButtonList></td></tr>aspx.cs code is :
string
img1 = "<img src='images/ <%# fixpicture(Container.DataItem(\"card"+Card.CardId+".jpg\")) %>'>"; ListItem listItem = new ListItem(img1, Card.CardId.ToString());rlCards.Items.Add(listItem);
I want my radiolist rlCards to be associated with the images in folder images and image name as (card+cardId).jpg
Is there any way, I can get that correctly.
Thanks in advance.
Rashmi
chope_07
Member
12 Points
6 Posts
Re: Radiobuttonlist Image Setting
Aug 17, 2009 09:55 AM|LINK
I know ot was too late then, but somebody might be looking for the same solution.
Maybe you could try this solution.
<asp:RadioButtonList id="RadioButtonList1" runat="server">
<asp:ListItem >
<%# "<img src=\"/pic_directory_here/" + fixpicture(Container.DataItem("pic_name_here").ToString()) + "\"" %>
</asp:ListItem>
</asp:RadioButtonList>
RadioButtonList Radiobuttonlist with Image
http://www.stringlist.com
tjaank
Contributor
3840 Points
698 Posts
Re: Radiobuttonlist Image Setting
Jun 15, 2010 05:24 PM|LINK
You can use following code for this purpose:
SqlCommand sqlCmd = new SqlCommand(); sqlCmd.CommandText = "select * from [YourTableName] Where SomeCondition = @someCondition"; sqlCmd.Parameters.AddWithValue("@someCondition", menuID); sqlCmd.CommandType = CommandType.Text; SqlConnection sqlCOn = new SqlConnection("Connection String.. bla bla"); sqlCOn.Open(); SqlDataAdapter adapter = new SqlDataAdapter(command); DataSet dsImages = new DataSet(); adapter.Fill(dsImages); sqlCOn.Close(); if (dsImages.Tables[0].Rows.Count != 0) { string imageFolder = "/imageFolder/"; foreach (DataRow dr in dsImages.Tables[0].Rows) { this.yourRadioButtonList.Items.Add(new ListItem(String.Format("<img src='{0}' width=\"100\" height=\"100\"><br />" + dr["Some_Database_Text"].ToString(), dr["Image_Path"].ToString()), dr["Image_Code"].ToString())); } } else { //Do Else }Please Mark as Answer if this post helps you!