在代码隐藏中的 asp:image 中显示数据表中的图像 [英] Display image from a datatable in asp:image in code-behind

查看:32
本文介绍了在代码隐藏中的 asp:image 中显示数据表中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表,它是从 1 行选择语句的结果集填充的(通过 SQL Server 2008 中的存储过程),它包含一个 Image 类型的列,我将图像存储在其中.

I have a datatable which is filled from the resultset of a 1 row select statement (via a stored procedure in SQL Server 2008) and it contains a Image typed column which I store images in.

我在 aspx 页面上有一个 asp:image 控件,我想将图像设置为该数据表的相应字段,但我不能做任何事情.请告诉我如何将 asp:image 设置为该数据表的图像列从后面的代码.

I have an asp:image control on an aspx page and i want to set the image to the corresponding field of that datatable but anything I do I can not. Please tell me how can I set the asp:image to image column of that datatable from the code behind.

推荐答案

尝试数据 URL 方案:

<img src="<%# ReturnEncodedBase64UTF8(Eval("ColumnA")) %>" />

protected static string ReturnEncodedBase64UTF8(object rawImg)
{
    string img = "data:image/gif;base64,{0}"; //change image type if need be
    byte[] toEncodeAsBytes = (byte[])rawImg;        
    string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);
    return String.Format(img, returnValue);
}

这篇关于在代码隐藏中的 asp:image 中显示数据表中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆