Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#Eval image data

How can I use Eval for binding sql varbinary data (images) to image? Something like this:

   <image src = <%# Eval("imageBinaryData") %> />

1 Answers

You need to use a HttpHandler to fetch the data and stream it back. You would then link to the handler from your ASPX page.

<img class="mainEventsImage" 
    src='<%# Eval("MainImagePath").ToString().Replace("\\", "/") %>' 
        alt='<%# Eval("Title") %>' runat="server" />

if (reader.Read())
{
    int bufferSize = 100;
    byte[] bytes = new byte[bufferSize];
    long bytesRead;
    long readFrom = 0;

    do
    {
        bytesRead = reader.GetBytes(0, readFrom, bytes, 0, bufferSize);
        context.Response.ContentType = "image/jpeg";
        context.Response.BinaryWrite(bytes);
        readFrom += bufferSize;
    }
    while (bytesRead == bufferSize);
}
reader.Close();
like image 169
IrishChieftain Avatar answered Jul 04 '26 05:07

IrishChieftain