Click here to Skip to main content
Click here to Skip to main content

Display images from a SQL database - the easy way

, 5 Jul 2008 Ms-PL
Rate this:
Please Sign up or sign in to vote.
This project contains a Web Custom Control for rendering images directly from the database. Can be used with image fields, text, date, or numerical fields (it generates an image containing the text), and with URL fields (like in a regular image control).


This is version 3.0 of the VsCustomRenderer control. You can find the previous versions here: 2.0 and 1.0.


This project was inspired by an article on CodeProject written by dev2dev: Create Dynamic Images in ASP.NET. Parts of the code were taken from that project.

Using the Code

To test this control:

  • Open or create a website.
  • Add the VSCustomRendererLibrary reference to the website.
  • Add the following line in the <httpHandlers> section in the web.config:
<add verb="*" path="*.jpg" 
  type="VSCustomRendererLibrary.VsImageHandler, VSCustomRendererLibrary"/>

If you cannot find this section in your web.config file, just create it under <system.web>:

          <add verb="*" path="*.jpg" 
            type="VSCustomRendererLibrary.VsImageHandler, VSCustomRendererLibrary"/>
  • Open/create a new ASPX page.
  • Add a SqlDataSource connected to a SQL table or view (this project was tested with SQL Server 2005 EE).
  • Add a GridView and connect it to the SqlDataSource.
  • In the GridView, add the image column and transform it into a template field.
  • Select Edit Template from the GridView toolbar menu.
  • Add a VSCustomRenderer into the ItemTemplate. Bind the control to the DataSource field.

Points of Interest

This Web Control now works with AJAX. This control no longer saves images to disk in order to display them. The pictures are displayed directly from memory through an IHttpHandler. This HTTP handler does not open a new database connection, it just displays the images from memory, so there are no delays in page rendering and no extra parameters to set.


All the versions of this control are also posted on CodePlex.


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

Software Developer (Senior)
Romania Romania
No Biography provided

Comments and Discussions

GeneralMy vote of 1 PinmemberDeian18-Mar-10 1:04 
QuestionFailure Pinmembervferrava29-Jul-08 12:09 
AnswerRe: Failure Pinmembereduguesser31-Jul-08 10:44 
GeneralRe: Failure PinmemberFF779-Nov-08 2:53 
GeneralAlternative PinmemberVitalyTomilov5-Jul-08 11:51 
GeneralRe: Alternative PinmemberFF775-Jul-08 11:58 
GeneralRe: Alternative PinmemberHoyaSaxa935-Jul-08 14:13 
GeneralRe: Alternative [modified] PinmemberVitalyTomilov6-Jul-08 2:46 
GeneralRe: Alternative PinmemberFF776-Jul-08 3:12 
GeneralRe: Alternative PinmemberVitalyTomilov6-Jul-08 12:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150129.1 | Last Updated 5 Jul 2008
Article Copyright 2008 by FF77
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid