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>
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0