Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #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...

Reply With Quote
  #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
Default

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:

Code:
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";
        context.Response.BinaryWrite(pictureData);
        context.Response.End();
    }
}
Then register your handler in web.config like this:

Code:
<system.web>
  <httpHandlers>
    <add path="pic.ashx" verb="GET" type="PictureLoader" />
  </httpHandlers>
  ...
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.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 12:49 AM
any idea to view xml as it is but in hieratic view seco XSLT 2 January 17th, 2008 07:49 AM
Help Grid View Drop Down List, view all jskinner123 ASP.NET 2.0 Basics 0 November 25th, 2007 05: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 04:13 AM



All times are GMT -4. The time now is 01:56 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.