I want to show Images in my datalist. Image URLs are stored in my database. For some reason urls can't be retrived from my database.
Anyone knows what Am I missing? Here is my code.
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatColumns="3" Width="100%">
<ItemTemplate>
<asp:Image runat="server" ImageUrl="http://mywebsite.com/folder/{0}" Width="100%" />
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [url] FROM [MyDatabase]"></asp:SqlDataSource>
There is problem in binding image to image control. Try this.
<asp:Image runat="server" ImageUrl='<%# "http://mywebsite.com/folder/" + Eval("url") %>' Width="100%" />
Or
<asp:Image runat="server" ImageUrl='<%# "~/folder/" + Eval("url") %>' Width="100%" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.