problem using Image control in DataList

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I am using Image control with DataList control but have a problem. Here is the code I am using

<asp:Image ImageURL='<%# DataBinder.Eval(Container.DataItem, "imagefilename" ) %>' Runat="Server" /

I would like to change it to something like this

<asp:Image ImageURL='images/<%# DataBinder.Eval(Container.DataItem, "imagefilename" ) %>' Runat="Server" /

In other words, I would like to add a folder name part to the ImageURL value. However it doesn't seem to work properly. What should I do

Thank you in advance

Vitalii
 
Try concatenating images/ with the Eval.

Not sure if you just need

&

or

&amp;
--
Joe Fallon



Vitalii said:
Hi,

I am using Image control with DataList control but have a problem. Here is the code I am using:

<asp:Image ImageURL='<%# DataBinder.Eval(Container.DataItem,
"imagefilename" ) %>' Runat="Server" />
I would like to change it to something like this:

<asp:Image ImageURL='images/<%# DataBinder.Eval(Container.DataItem,
"imagefilename" ) %>' Runat="Server" />
In other words, I would like to add a folder name part to the ImageURL
value. However it doesn't seem to work properly. What should I do?
 
Vitalii

Create a function in the code behind and call it from the databinding. It
will look like this:

'---Code behind function:
Public Function GetImagePath(ByVal imageFileName As String) As String
Return "images/" & imageFileName
End Function

Then on the calling page call this function passing in the data:
<asp:Image ImageURL='<%# GetImagePath(DataBinder.Eval(Container.DataItem,
"imagefilename" )) %>' Runat="Server" />

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
Vitalii said:
Hi,

I am using Image control with DataList control but have a problem. Here is the code I am using:

<asp:Image ImageURL='<%# DataBinder.Eval(Container.DataItem,
"imagefilename" ) %>' Runat="Server" />
I would like to change it to something like this:

<asp:Image ImageURL='images/<%# DataBinder.Eval(Container.DataItem,
"imagefilename" ) %>' Runat="Server" />
In other words, I would like to add a folder name part to the ImageURL
value. However it doesn't seem to work properly. What should I do?
 
hi try this on
<%#Server.MapPath(@"\images"+DataBinder.Eval(Container.DataItem, "imagefilename")%>
 
Back
Top