How can i load an image into A Image control from sql database from sql server? The image is stored in image format... Image control is in repeater Code in repeater
<table id="tableposts" style="text-align: center; width: 100%; height: 80%;">
<tr>
<td>
<asp:LinkButton ID="lbpostusername" runat="server"
Text='<%#Eval("UserName") %>'>
</asp:LinkButton>
</td>
</tr>
<tr>
<td>
<asp:Label ID="posthead" runat="server"
Text='<%#Eval("PostHead") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<p id="postcontent"><%#Eval("PostContent") %></p>
</td>
</tr>
<tr>
<td>
<asp:Image ID="postimage" runat="server" ImageUrl=""/>
</td>
</tr>
</table>
Code to retrieve values
private DataSet GetData()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LoginConString"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("Select PostID,UserName,PostHead,PostContent,PostImage from Posts WHERE USERID ='" + Session["New"].ToString() + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
postids = ds.Tables[0].Rows[0].ToString();
return ds;
}
TRY THIS
public string GetImageFromByte(object byt)
{
byte[] byts = (byte[])byt;
return byteArrayToImage(byts);
}
Instead of
public string GetImageFromByte(object byt)
{
byte[] byts = Convert.ToByte(byt);
return byteArrayToImage(byts);
}
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.