Not sure how to explain this but I have a mysql syntax odbc connection bound to a sqldatasource like so:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ODBCDataConnectionString %>"
ProviderName="<%$ ConnectionStrings:ODBCDataConnectionString.ProviderName %>"
SelectCommand="SELECT User.FirstName, User.SecondName, User.Aboutme, User.DOB, Pictures.picturepath FROM User LEFT JOIN Pictures ON User.UserID = Pictures.UserID">
</asp:SqlDataSource>
I save the Image*URL* to the database and im trying to change part of my listview so I can display that image, every attempt ive tryed either results in server tag not well formed if I use an asp image or only the url path being displayed if i use a html img control. How can I combat one of these so I can display images via a imageurl in my listview?
<asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1"
EnableModelValidation="True" GroupItemCount="3">
<AlternatingItemTemplate>
<td runat="server" style="background-color:#FFF8DC;">
FirstName:
<asp:Label ID="FirstNameLabel" runat="server" Text='<%# Eval("FirstName") %>' />
<br />SecondName:
<asp:Label ID="SecondNameLabel" runat="server"
Text='<%# Eval("SecondName") %>' />
<br />Aboutme:
<asp:Label ID="AboutmeLabel" runat="server" Text='<%# Eval("Aboutme") %>' />
开发者_如何学Go <br />
DOB:
<asp:Label ID="DOBLabel" runat="server" Text='<%# Eval("DOB") %>' />
<br />
picturepath:
<img alt="" src="<%# Eval("picturepath") %>" />
<%--<asp:Image ID="Image1" runat="server" ImageUrl="<%# Eval("picturepath") %>" />--%>
<%-- <asp:Label ID="picturepathLabel" runat="server"
Text='<%# Eval("picturepath") %>' />--%>
<br />
</td>
You can not use a server control in template part of other server controls.
but the only solution is inserting img tag in your template. but a problem still remains. your image url maybe have ~ indicating application Path.
You can use code bellow to correct this problem too.
<img alt="" src="<%# Eval("picturepath").Tostring()
.Replace("~/", "http://" + Request.Url.Host + "/" +
(string.IsNullOrEmpty(Request.ApplicationPath)?
string.Empty:Request.ApplicationPath + "/") %>" />
This will correct your problem
Change double quotes " " to single quote ' ':
src="<%# Eval("picturepath") %>" />
to
src='<%# Eval("picturepath") %>' />
精彩评论