0

i want to achievet the following Url

ImageUrl='~/products_pictures/(imageId)_middle.jpg

im using gridview and datalist

im trying the follwoing combination but it not working

  <asp:Image ID="Image1"  ImageUrl='~/products_pictures/<%#Eval("Id")%>_middle.jpg' runat="server" /></td>


 <asp:Image ID="Image1"  ImageUrl=<%"~/products_pictures/"%><%#Eval("Id")%><%"_middle.jpg"%> runat="server" />

5 Answers 5

3

I would use String.Format for this. It makes concatenation much easier:

<asp:Image ID="Image1" runat="server" ImageUrl='<%# String.Format("~/products_pictures/{0}_middle.jpg", Eval("ID"))%>'
Sign up to request clarification or add additional context in comments.

Comments

0

this should work:

</td><asp:Image ID="Image1"  ImageUrl="~/products_pictures/<%#Eval("Id")%>_middle.jpg" runat="server" /></td>

if not debug from this:

</td><%#Eval("Id")%></td>

ells you can try

 <%# ((objectName)Container.DataItem).Id%>
((DataRowView)Container.DataItem)["Id"]

Comments

0

This might work

<asp:Image ID="Image1" runat="server" ImageUrl="~/products_pictures/<%#Eval("id") %>_middle.jpg"/>

If not you can put a asp:Literal, and a HiddenField to store id and in GridView.RowDataBound Event you can add image as a text to the literal

1 Comment

it not working when i try to rebuild my project it giving me error Error The server tag is not well formed
0

The server tag is not well formed because of the quotes

put single quotes on the outside and try again

ImageUrl='~/products_pictures/<%#Eval("Id")%>_middle.jpg'

1 Comment

the problem im having when i check the code behind web page it adding extra bit src="products_pictures/%3C%25#Eval(%22Id%22)%25%3E_middle.jpg"
0

This worked at my end:

<asp:Image ID="Image1" runat="server" ImageUrl="<%#'~/products_pictures/' + Eval("id")+'_middle.jpg' %>"/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.