#Eval image data

左心房为你撑大大i 提交于 2019-12-10 19:04:46

问题


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

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

回答1:


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();


来源:https://stackoverflow.com/questions/13018623/eval-image-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!