#Eval图像数据

时间:2012-10-22 19:43:45

标签: asp.net image eval

如何使用Eval将sql varbinary数据(图像)绑定到图像? 像这样:

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

1 个答案:

答案 0 :(得分:1)

您需要使用HttpHandler来获取数据并将其重新流回。然后,您将从ASPX页面链接到处理程序。

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