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:
SELECTStudyID, 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.
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.
Thanks for the tips. Yes this is a read-only calculated field so users can't hack in any html code.
Whereas the included example in the documentation has overwriting the loading event codes, etc, this was so easy I assumed I was "cheating" or something. I don't know why the manual shows the hardest way to do this.