bind database image to ItemTemplate in .ascx

别来无恙 提交于 2019-12-02 09:07:02

You could use an "inline image". The technique is described at for instance Base64 encoded images embedded in html (search for base64 image html for other resources).

Get the base64-encoded string of the image data bytes, using Convert.ToBase64String for instance, and then use <img src=data:image/gif;base64, and append the image data.

So you can bind it using something like this

<img src='<%# string.Format("data:image/gif;base64,{0}",
 Convert.ToBase64String((byte[])Eval("ImageDataBase64")))%>'/>

Of course, this is only recommended for small images. Also note that you should change "gif" to the actual format of your image.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!