image control. I've had read some articles and watch video tutorial which there were perfectly
working and I followed it but I wasn't able to make it work. The image control just displayed blank.
I used Generic Handler to retrieve the image file from my database based on the articles and tutorials
I've got.I'll show you below my codes and please help me point out what did I miss?
Thanks for any help...here are my codes below:
Generic Handler:
<%@ WebHandler Language="C#" Class="ShowImage" %>
using System;
using System.Configuration;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web;
using System.IO;
using System.Data;
using System.Data.SqlClient;
public class ShowImage : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if (context.Request.QueryString["ID"] == null) return;
//string connStr = ConfigurationManager.ConnectionStrings["connStr"].ToString();
string connStr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Coldwind.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
string ID = context.Request.QueryString["ID"];
using (SqlConnection conn = new SqlConnection(connStr))
{
using (SqlCommand cmd = new SqlCommand("Select Photos From ProfileTab Where ID =" + ID, conn))
{
//cmd.Parameters.Add(new SqlParameter("@ID",ID));
conn.Open();
using (SqlDataReader reader = cmd.ExecuteReader(Commandbehavior.CloseConnection))
{
reader.Read();
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite((Byte[])reader[reader.GetOrdinal("Photos")]);
// byte[] imgData = (byte[])reader["Photos"];
// context.Response.BinaryWrite(imgData);
reader.Close();
}
}
}
}
public bool IsReusable
{
get
{
return true;
}
}
}
Asp.Net Code for the Image control:
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "ShowImage.ashx?ID=" + Eval("ID") %>' Height="128px" />

New Topic/Question
Reply



MultiQuote




|