绑定数据库图像的ItemTemplate中的.ascx [英] bind database image to ItemTemplate in .ascx
问题描述
我使用从database.Here填充的ListView的ItemTemplate动态是我该怎么办时,我需要显示字符串列Parametr(或其他数据类型):
//我.ascx文件
<立GT;<%#的eval(Parametr)%> < /李>
我
如何显示保存图像VARBINARY列?谢谢。
编辑:
下面是一些code,如果有人需要的:
< ASP:ListView控件...的DataSourceID =数据库>< / ASP:的ListView>
< ASP:SqlDataSource的... ID =数据库的SelectCommand =选择image_table图像>< / ASP:SqlDataSource的>
您可以使用内嵌图像。该技术在被描述为实例的的Base64连接嵌入在HTML $ C $光盘镜像(搜索对其他资源的base64形象HTML)。
获取图像数据字节的base64恩codeD字符串,使用的 Convert.ToBase64String 例如,然后用< IMG SRC =数据:图像/ GIF; BASE64,
并追加图像数据
所以,你可以使用像这样绑定
< IMG SRC ='<%#的String.Format(数据:图像/ GIF; BASE64,{0},
Convert.ToBase64String((字节[])的eval(ImageDataBase64)))%GT;/>
当然,这只是建议小型图像。还要注意的是,你应该改变GIF你的形象的实际格式。
I am using dynamic ItemTemplate for ListView which populated from database.Here is how I do when I need to display string column "Parametr" (or some other datatypes):
//my .ascx file
<li><%# Eval("Parametr") %> </li>
How can I display varbinary column that stores images?Thanks.
EDIT:
Here is some more code if somebody needed:
<asp:ListView ... DataSourceID="database" ></asp:ListView>
<asp:SqlDataSource ... ID="database" SelectCommand="SELECT image FROM image_table"></asp:SqlDataSource>
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.
这篇关于绑定数据库图像的ItemTemplate中的.ascx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!