I am need to display an image on my asp.net page, which is stored as an image data type in SQL Server. I am looking at this post, display/retrieve image from sql database in vb.net, however, how can I display that image in a <td>
element?
Asked
Active
Viewed 4,233 times
0
2 Answers
3
<td>
tags can't be used to display images unless you put an <img>
element inside it. With that said, this is how you display an image in VB.NET from code behind:
Having this type of markup in your aspx page:
<td>
<img src="" runat="server" id="imageFromDB" />
...
You can do this in code behind:
Dim imageBytes() as Byte= ... // You got the image from the db here...
//jpg is used as an example on the line below.
//You need to use the actual type i.e. gif, jpg, png, etc.
//You can do imageFromDB simply because you set runat="server" on the markup
imageFromDB.src = String.Format("data:image/{0};base64,
{1}","jpg",Convert.ToBase64String(imageBytes)
And this will render your image on the page.
I hope I've given you enough information here.

Icarus
- 63,293
- 14
- 100
- 115
1
Referring to the sample in the answer you mention:
<td><img src="PathToYourHttpHandler?id=ID_OF_YOUR_IMAGE" /></td>

Jan
- 15,802
- 5
- 35
- 59