0

Image control with the ImageUrl bound from DataSource1.

<asp:Image ID="image" runat="server" ImageUrl='<%# Eval("CandidateId", "Picture") %>' />

Below is the DataSource1, brings the Picture field. But the Picture field in the database does not have the full path. It keeps the part of it like: pictures/1250/candidatepicture.jpg. Full path is sth like: http://abc.storage/pictures/1250/candidatepicture.jpg.

<asp:SqlDataSource ID="DataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
 ProviderName="System.Data.SqlClient" SelectCommand="SELECT CandidateId, Picture, Name FROM [Candidates] WHERE ([CandidateId] = @CandidateId)">
 <SelectParameters>
      <asp:Parameter Name="CandidateId" Type="Int32" />
 </SelectParameters>

So when I am using Eval, I need to do sth like ImageUrl='<%# Eval("CandidateId", "http://abc.storage/" + "Picture") %>'. But obviously this does not work.

What's the way to do?

1 Answer 1

2

In this form Eval accepts name of the column you need to retrieve and, optionally, the format of the resulting string. If you need to get two fields out of current data item - you need two Eval calls for this. However in your case one column Picture seems to suffice:

ImageUrl='<%# string.Format("http://abc.storage/{0}", Eval("Picture")) %>'
Sign up to request clarification or add additional context in comments.

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.