在listview中通过imageurl显示图像 [英] display image via imageurl in listview
问题描述
不知道如何解释这一点,但我有一个mysql语法odbc连接绑定到sqldatasource像这样:
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>
我将Image * URL *保存到数据库中,并试图改变我的列表视图的一部分,所以我可以显示该图像,每次尝试ive尝试要么导致服务器标记不正确形成,如果我使用一个ASP图像或只有URL路径显示,如果我使用HTML IMG控制。
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") %>' />
<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.
但唯一的解决方案是在您的模板中插入img标签。但问题仍然存在。您的图片网址可能有指示应用程序路径的〜。
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
这篇关于在listview中通过imageurl显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!