problem using Image control in DataList

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
 
J

Joe Fallon

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?
 
S

S. Justin Gengo

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?
 
G

Guest

hi try this on
<%#Server.MapPath(@"\images"+DataBinder.Eval(Container.DataItem, "imagefilename")%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,219
Latest member
KristieKoh

Latest Threads

Top