I would like to of display an the image at a proper position on a browser.  I access the image from the database before doing this I stored the image in a database in a byte form. I also make a functionality of add image in a database.
When i retrieve the image from the database onliy image is displayed on a browser . The form from which I add the image is not displayed.
This is the aspx page coding
	That is the .cs page coding
	
							
						
					When i retrieve the image from the database onliy image is displayed on a browser . The form from which I add the image is not displayed.
This is the aspx page coding
Code:
	<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ins_Image_in_DB.aspx.cs" Inherits="ImageDemo" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
<h1>Insert Image In Database</h1>
    <div id="dv_visible" runat="server">    
    <form id="form1" runat="server" method="post">
    <div>
    <table border="3" cellspacing="3" width="300px">
    <tr>
    <td>
    <b>Image_Name</b>
    </td>
    <td>
    <asp:TextBox ID="txtImageName" runat="server" ></asp:TextBox>
  </td>
 </tr>
     <tr><td>
     <b>ImageUpload</b>
     </td>
     <td>
    <asp:FileUpload ID="UploadImage" runat="server" />
    </td>
    </tr>
    <tr>
    <td colspan="2" align="right">
    <asp:Button ID="AddImage" runat="server" Text="InsertImage" Font-Bold="true" 
            onclick="AddImage_Click"/>
    </td>
     </tr>
    </table>
    <asp:Label ID="Message" runat="server"></asp:Label>
    </div><h1>Select Image</h1>
    <asp:DropDownList ID="ddlImageDisplay" runat="server" AutoPostBack="True"></asp:DropDownList>
    
   
    </form>
    </div>
    <div>
    <asp:Image ID="DisplayImage" runat="server" ImageUrl="Ins_Image_in_DB.aspx" />
   <%--  <img src="Ins_Image_in_DB.aspx" alt="image not dispalyed"/>--%>
    </div>
    
    
    </body>
</html>
Code:
	using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Collections.Generic;
using BllDummy;
public partial class ImageDemo : System.Web.UI.Page
{
    DummyBLL dummy = new DummyBLL();
    protected void Page_Load(object sender, EventArgs e)
    {
        dv_visible.Visible = true;
        if (!Page.IsPostBack)
        {
            dropdownImagelist();
        }
       selectedImagedisplay();
    }
    protected void AddImage_Click(object sender, EventArgs e)
    {
         Stream imgStream = UploadImage.PostedFile.InputStream;
         int ImgLength= UploadImage.PostedFile.ContentLength;
         dummy.ImageName = txtImageName.Text;
         dummy.ImageContentType = UploadImage.PostedFile.ContentType;
         byte[] imageType = new byte[ImgLength];
         dummy.ImageType = imageType;
         int n = imgStream.Read(imageType, 0, ImgLength);
         int roweffected= dummy.addImage();
         if (n >= 0)
             Message.Text = "Image Is Saved In a database";
         else
             Message.Text = "error Occur";
        
    }
    private void dropdownImagelist()
   {
        List<DummyBLL> ListImages = dummy.DisplayImage();
        ddlImageDisplay.Items.Add(new ListItem("--SelectImage---", "0"));
        foreach (DummyBLL ImageObject in ListImages)
        {
            ddlImageDisplay.Items.Add(new ListItem(ImageObject.ImageName.ToString(), ImageObject.ImageId.ToString()));
        }
    }
        private void selectedImagedisplay()
        {
            List<DummyBLL> ListImages = dummy.DisplayImage();
            foreach (DummyBLL ImageObject in ListImages)
            {
                if (ImageObject.ImageId.ToString() == ddlImageDisplay.SelectedValue)
                {
                    dummy.ImageId = ImageObject.ImageId;
                    dummy = dummy.displayImage();
                    Response.ContentType = dummy.ImageContentType;
                    Response.BinaryWrite(dummy.ImageType);
                    break;
                }
            }
    }
}
Comment