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

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

最佳答案

您需要使用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();

关于asp.net - #评估图像数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13018623/

10-09 08:50