Hi all
I m using asp.net 4.0. In my data list i have used asp image tag like below

<asp:Image ID="imgSmallPics" runat ="server" ImageUrl ='~/AdsPictures/<%#Eval("pictureName")%>'

where AdsPictures is folder where images resides and pictureName is name of image return by query.

Image is not shown, when i copy url of image its http://localhost:2846/AdsPictures/%3C%25#Eval(%22pictureName%22)%25%3E

but when i use html image tag

<img src ="../AdsPictures/<%#Eval("PictureName") %>" width ="44" height ="45" />

its working fine.

How can i achieve it through asp image tag.

Regards

Hi,

Try this

<asp:Image ID="imgSmallPics" runat ="server" ImageUrl ='<%# "~/AdsPictures/" & Eval("pictureName")%>'

Actually, I too used to have problem on attaching Eval methods with server side and pure html controls. :)

Hope this works.
Thanks,

Hi

Yours code results in following error:
Compiler Error Message: CS0019: Operator '&' cannot be applied to operands of type 'string' and 'object'

I don't think i need AdsPicture inside <%#%> tags.

Hi,
That is not by placing "~/AdsPictures/" but due to the fact that you concatenate string with unknown object.

Relace your block with this.

<asp:Image ID="imgSmallPics" runat ="server" ImageUrl ='<%# "~/AdsPictures/" & DataBinder.Eval(Container, "DataItem.pictureName").ToString()%>' ></asp:Image>

Thanks,

Well in VS 2010 the operator "&" used for concatenation gave same error which i mentioned in previous post however it works with "+" operator. Below code works fine for me:

<asp:Image ID="imgSmallPics" runat ="server" ImageUrl ='<%# "~/AdsPictures/" + Eval("PictureName")%>'  width ="44" height ="45" />

I think "&" will work in older version of .net(not sure about this)

Thank you prashantchalise for this nice piece of code.

this url is not working for me. image boxes appear on page load and then disappear immediately.don't know why

<asp:ListView runat="server" ID="listView"> 

                            <ItemTemplate>

                           <asp:Image ID="img"  ImageUrl= '<%# "/" + Eval("PictureLink")%>' width ="44" height ="45" runat="server" />


                            </ItemTemplate>
                            </asp:ListView>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.