0

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?

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Referring to the sample in the answer you mention:

<td><img src="PathToYourHttpHandler?id=ID_OF_YOUR_IMAGE" /></td>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.