<asp:Image ID="Image1" ImageUrl='<%# "ImageHandler.ashx?id=" + Eval("gname")%>' Width="300px" Height="220px" runat="server" /></td>
</asp:DataList>server side coding:Da_Layer DL = new Da_Layer();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string query = "select * from gallery";
DataSet ds = DL.Grid(query);
DataList1.DataSource = ds.Tables[0];
DataList1.DataBind();
}
}
ImageHandler.ashx coding:<%@ WebHandler Language="C#" Class="ImageHandler" %>
using System;
using System.Web;
using System.Data.SqlClient;
public class ImageHandler : IHttpHandler {
Da_Layer DL = new Da_Layer();
public void ProcessRequest (HttpContext context)
{
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
string query = "select * from gallery where gname='"+context.Request.Params["id"]+"'";
SqlDataReader dr = DL.ExecuteReader(query);
dr.Read();
Byte[] Imagedata = (byte[])dr["gphoto"];
// context.Response.BinaryWrite(dr["gphoto"]);
context.Response.BinaryWrite(Imagedata);
dr.Close();
}
public bool IsReusable {
get {
return false;
}
}
}i change context.Request.Params["id"] and directly give input for select query and i run ImageHandler.ashx it give the Output System.byte[]but correct answer it need to give some binary values in browserWhat is the problem...... in this application i used both c# and vbalso i used this coding for convert binary value from database to image,it also not give correct answer,my question is if i want read binary value any change need web.config fileDL.OpenConnection();
FileStream fs = new FileStream(@"c:\xx.jpg", FileMode.CreateNew, FileAccess.Write);
cmd = new SqlCommand("select * from staffdetails where staff_id='" + txt_id.Text + "'", DL.connection);
dr = cmd.ExecuteReader();
if (dr.Read())
{
byte[] b = (byte[])(dr["photo"]);
fs.Write(b, 0, b.Length);
}
fs.Close();
DL.CloseConnection();
GridView1.Visible = false;
DetailsView1.Visible = true;
DetailsView1.DataBind();