my gridview displays only text not image
my cs file is
private void BindImageGridData()
{
SqlCommand command = new SqlCommand("select empcode,EmpPhoto from tblEmpImg where empcode='"+txtempcode.Text+"'", con);
SqlDataAdapter daimages = new SqlDataAdapter(command);
DataTable dt = new DataTable();
daimages.Fill(dt);
grdEmployee.DataSource = dt;
grdEmployee.DataBind();
}
and my ImageHandler.ashx is
<%@ WebHandler Language="C#" Class="ImageHandler" %>
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public class ImageHandler : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conNatcoSal"].ConnectionString.ToString());
string imageid = context.Request.QueryString["Id"];
con.Open();
// SqlCommand command = new SqlCommand("select Image from Employee where Id=" + imageid, connection);
SqlCommand command = new SqlCommand("select empcode, EmpPhoto from tblEmpImg where empcode="+ imageid ,con);
SqlDataReader dr = command.ExecuteReader();
dr.Read();
context.Response.BinaryWrite((Byte[])dr[0]);
con.Close();
context.Response.End();
}
public bool IsReusable
{
get {
return false;
}
}
}
......finaly aspx page is
<%--
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Midhun TpPosted Oct 20, 2016, 7:28 AM
Amit GuptaPosted Oct 20, 2016, 6:59 AM