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?

4

1 回答 1

2

在这种形式Eval中,接受您需要检索的列的名称,以及结果字符串的格式(可选)。如果您需要从当前数据项中获取两个字段 - 您需要Eval为此调用两次。但是,在您的情况下,一列Picture似乎就足够了:

ImageUrl='<%# string.Format("http://abc.storage/{0}", Eval("Picture")) %>'
于 2014-07-22T10:49:32.227 回答