Hello, i am working asp.net fetch image program in the database, image should be store in BLOB form so i want to display image in asp.net page in single side. when i called Response.BinaryWrite() method it is display full page in asp.net, i want display only single side in the page. thanks in advance.
Best bet would be adding an httphandler (they have the extension ashx) and can be added from the Add New Item menu in visual studio. A handler for your app would look something like this. Handler.ashx file to perform image retrieval. This Handler.ashx page will contain only one method called ProcessRequest. This method will return binary data to the incoming request. In this method, we do normal data retrieval process and return only the Image_Content field as bytes of array. The sample code follows public void ProcessRequest (HttpContext context) { SqlConnection myConnection = new SqlConnection(“YourConnectionStringâ€); myConnection.Open(); string sql = "Select Image_Content, Image_Type from ImageGallery where Img_Id=@ImageId"; SqlCommand cmd = new SqlCommand(sql, myConnection); cmd.Parameters.Add("@ImageId", SqlDbType.Int).Value = context.Request.QueryString["id"]; cmd.Prepare(); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); context.Response.ContentType = dr["Image_Type"].ToString(); context.Response.BinaryWrite((byte[])dr["Image_Content"]); dr.Close(); myConnection.Close(); } To use this method your image source will be the handler. Example: <asp:TemplateField> <ItemTemplate> <asp:Image ID="Image1" runat="server" ImageUrl='<%# "Handler.ashx?id=" + Eval("Img_Id") %>' /> </ItemTemplate> </asp:TemplateField> A complete sample can be found aspdotnetcodes_com/Insert_Images_Database.aspx I would also recommend the original Asp.net (found as asp dot net) classified starter kit to learn about binary image storage and retrieval for display, it is very thorough.
I agree that handler would be the way to go if you want to/ have to store images in DB. However I would highly recommend storing images in the file system instead.