This is my code in aspx file
cnn.Open();
SqlDataAdapter da1 = new SqlDataAdapter(\"select * from carousel\", cnn);
DataTable dt1 = new DataTable();
d
You need to convert in URI for IMG HTML tag:
<img src="<%# System.Text.Encoding.ASCII.GetString(Eval("bynarydatacolumn")) %>" />
or equivalent.
This is because the value coming from the database is a byte array representing the actual data of the image. Whereas the src
of an img
tag expects a URL to an image. There are essentially two ways to go about this...
src
attribute.There are lots of tutorials for the first option online. This one was found by a quick Google search, there are others as well. Essentially what the handler would do is accept an identifier on the query string, use that identifier to get the image from the database, then write the appropriate headers and content to the response. The URL for the src
attribute would then be that handler. Something like:
ImageUrl='<# "~/handler.ashx?id=" + Eval("id") #>'
(Or whatever your data-bound data uses as an identifier for the image.)
suppose your image column name in database "ImageName" then
Solution 1:if your image in Root Folder
<img src='<%#Eval("ImageName")%>' alt="" />
OR
<asp:Image ID="Image1" ImageUrl='<%#Eval("ImageName")%>' runat="server" />
Solution 2:if your image in images Folder
<img src='<%# "images/" + Eval("ImageName") %>' alt=""/>
OR
<asp:Image ID="Image1" ImageUrl='<%# "images/" + Eval("ImageName") %>' runat="server" />
Your Final Solution:
<asp:Repeater id="Rp1" runat="server">
<ItemTemplate>
<div class="item">
<img src='<%#Eval("ImageName")%>' alt="" />
OR
<asp:Image ID="Image1" ImageUrl='<%# "images/" + Eval("ImageName") %>' runat="server" />
</div>
</ItemTemplate>
<footertemplate></footertemplate>
</asp:Repeater>