显示图像列表视图中的数据表,从 [英] Showing an image in listview from datatable

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

问题描述

我有一个图像类型的列的SQL Server 2008的表,我用它来存储图像(SQL图像类型)。

I have a SQL Server 2008 Table with an image typed column which I use to store images in (in SQL Image Type).

我有上有一个列表视图这势必是从包括图像查询填充DataTable的ASPX页面。而数据表中充满图像字段的值是牵强。

I have an ASPX page with a listview on it which is bound to a datatable which is filled from a query that includes that image. The value of image field is fetched while the datatable is filled.

现在我要显示图像为列表视图的各个领域。我使用<%#的eval(ColumnA)%> 的语法,显示从该查询提取文本,但我不知道如何从该查询显示图像。 (例如使用的控制?使用的语法?)

Now I want to show the image for each field of that list view. I use <%# Eval("ColumnA") %> like syntax to show texts fetched from that query but I do not know how to show the image from that query. (e.g. using which control? using which syntax?)

推荐答案

尝试数据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);
}

这篇关于显示图像列表视图中的数据表,从的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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