Is Dot Net version 2.0 support generic handler? I am trying to retrieve binary image from database to gridview but it's not showing any image. Or not showing me any error.
Gridview Photo Cloumn :
<asp:TemplateField HeaderText="Image">
<ItemTemplate >
<asp:Image ID="Image1" Height="100px" Width="100px" runat="server" ImageUrl='<%#"ImageHandler.ashx?id_Image="+Eval("ImageId")%>'/>
</ItemTemplate>
</asp:TemplateField>
Generic Handler :
<%@ WebHandler Language="C#" Class="ImageHandler" %>
using System;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Collections;
using CSC.Common;
using CSC.DL;
using System.Configuration;
using System.Collections.Generic;
using System.IO;
using log4net;
using System.Text;
public class ImageHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string imageid = "";
if (context.Request.QueryString["id_Image"] != null)
{
imageid = context.Request.QueryString["id_Image"].ToString();
}
SqlConnection connection = null;
//SqlCommand cm = null;
DataReader dr = new DataReader();
DataTable dt = new DataTable();
connection = new SqlConnection();
connection.ConnectionString = "Data Source=datasource;Initial Catalog=myDb;User ID=user;Password=myPass";
connection.Open();
//connection = new SqlConnection(ConfigReader.LoginConnString);
String stringsql = string.Format("Select photo from tblPhoto", imageid);
dt = dr.GetDataTableByCommand(stringsql, connection);
if (dt.Rows.Count > 0)
{
context.Response.BinaryWrite((Byte[])dt.Rows[0]["photo"]);
context.Response.End();
connection.Close();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
When gridview bind photo cloumn then it will can ImageHandler class and it will retrive binary image from DB and convert it to image and pass it to gridview. I am using this but it's not showing any image in gridview. There is no error found in my project.