0

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

3
Contributors
5
Replies
10
Views
6 Years
Discussion Span
Last Post by eesha.ebaad
0

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,

0

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.

0

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,

0

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.

0

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>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.