我有一个指向 asp.net 中转发器控件的 linq 数据源
。
我想显示存储在数据库表中的图像。
当我使用此代码时,我在其他表中有一个类别表和产品表
<% Eval("CategoryImage")%> .
它在浏览器中显示 System.byte[]
,当我使用带有 Eval();
的 ASP 图像控件时,它会给我一个常见的损坏图像图标。
有人可以建议我一种通过linq数据源直接从
mysql数据库
本身插入图像的方法..
我怎样才能在堆栈溢出和asp标签中格式化html标签..
提前感谢帮助...
最佳答案
您可以使用此功能
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
将字节数组转换为图像。
如果 Eval("CategoryImage")
中有字节数组
,那么您也可以从 Eval
调用此函数。
作为
<%# byteArrayToImage(Eval("CategoryImage"))%>
未经测试,但应该可以工作。
编辑 1
这是一个很好的链接
argumentException was unhandled error when converting byte of array to image
How to convert byte array to image and display in datagrid?
关于asp.net - 在转发器控件中显示来自 linq 数据源的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15174036/