<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"> <Columns> <asp:BoundField DataField="id" HeaderText="Id" /> <asp:BoundField DataField="name" HeaderText="Name" /> <asp:TemplateField HeaderText="Picture"> <ItemTemplate> <img src="Handler1.ashx?Id=<%# Eval("id").ToString() %>" width="150" height="100" /> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
protected void ShowFromDatabase(object sender, EventArgs e) { string str2 = "select id,name from tbl_image"; obj.dr = obj.ret_dr(str2); GridView1.DataSource = obj.dr; GridView1.DataBind(); }
public class Handler1 : IHttpHandler { Class1 obj = new Class1(); public void ProcessRequest(HttpContext context) { //context.Response.ContentType = "text/plain"; //context.Response.Write("Hello World"); string pid=context.Request.QueryString["Id"]; string str = "select picture from tbl_image where id='"+pid+"'"; obj.dr = obj.ret_dr(str); while (obj.dr.Read()) { context.Response.ContentType = "image/jpg"; //context.Response.BinaryWrite((Byte[])obj.dr[obj.dr.GetOrdinal("picture")]); context.Response.BinaryWrite((Byte[])obj.dr["picture"]); } } public bool IsReusable { get { return true; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)