Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 8th, 2008, 06:58 AM
Registered User
Join Date: Apr 2008
Location: ipoh, perak, Malaysia.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to view picture by using form view?

i wish to use form view to display data that binding to database, the problem is how to display picture by using form view? can anyone solve my problem? thanks...

  #2 (permalink)  
Old April 8th, 2008, 07:17 AM
Authorized User
Join Date: Sep 2007
Location: , , Finland.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts

Here is one way to do it. First add Image control to the view:

<asp:Image runat="server" ImageUrl='<%# Eval("PictureID", "pic.ashx?id={0}") %>' />

Take notice image's url: pic.ashx?id=<picture id>

When browser sees this, it calls back the server to download the image. Then write custom HTTP handler to spout out the image:

public class PictureLoader : IHttpHandler
    bool IHttpHandler.IsReusable { return false; }

    void IHttpHandler.ProcessRequest(HttpContext context)
        SqlConnection conn = ...
        SqlCommand cmd = 
            new SqlCommand("SELECT PictureData FROM Pictures WHERE PictureID = @id", conn);

        byte[] pictureData = (byte[])cmd.ExecuteScalar();

        context.Response.StatusCode = 200;
        context.Response.AddHeader("Content-Length", pictureData.Length.ToString());
        context.Response.ContentType = "image/jpeg";
Then register your handler in web.config like this:

    <add path="pic.ashx" verb="GET" type="PictureLoader" />
And because I'm lazy writer remember to check from MSDN what all those custom handlers are/do and you get a clearer picture about all of this.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent - Send mail with plain view and html view ashish.dadhwal ASP.NET 2.0 Professional 0 November 27th, 2008 01:49 AM
any idea to view xml as it is but in hieratic view seco XSLT 2 January 17th, 2008 08:49 AM
Help Grid View Drop Down List, view all jskinner123 ASP.NET 2.0 Basics 0 November 25th, 2007 06:25 PM
populate details view or list view non empty rows iinfoque ASP.NET 2.0 Basics 0 March 11th, 2007 06:11 AM
View .jpg with Windows Picture and Fax Viewer mmcdonal Access VBA 1 March 10th, 2006 05:13 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.