Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
110
Anything wrong with directly putting img src code in cell?
posted

I'm able to display images in a column but simply having the column values be an html image tag. (e.g. <img src="12345.jpg">).  This seems too easy. I can easily display custom images without any extra grid code by having my database view return the image tag string.

Is there anything wrong with this method as opposed to setting the Style.Background field programmatically?

For those interested, here's an example of my TableAdapter view:

SELECT
StudyID,
ScenarioID,
'Screenshot'='<img src="images/' + StudyID+'.jpg' + '">'
 FROM dbo.Studies order by StudyID

In the grid, I didn't have to do anything special for the "Screenshot" column.  It shows the image as expected.  I can then set the cell padding to provide some space around the images.

 

Parents
No Data
Reply
  • 45049
    posted

    There should be nothing wrong with this approach at all.  It's the easiest way to put an image into a WebGrid cell.

    There are two caveats I can give:

    First, ensure that the HTMLEncodeContent property of your column is set to false (which is the case by default).  If you set this property to true, then the HTML tag in your column will appear as plain HTML text, not parsed as an image.

    Second, you probably don't want to allow the user to update on this column.  A user would only be able to update cells in this column as raw HTML, and I wouldn't expect that HTML to be parsed until the page posts back.

Children