Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
3.33/5 (3 votes)
I am trying to show original image as popup when i click on small image, I have sql table in which I store image as blob then I display this image in a img control but now I want when user click on this image it will open in bigger size popup.
my code to retreive image from database and display in img control is:
ASP.NET
<img  runat="server" id="image1" alt="" src="" height="100" width="100"/>

C#
protected void LoadImage1()
    {
        SqlCommand cmd = new SqlCommand("sps_getimage", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@flag", 1);
        cmd.Parameters.AddWithValue("@ad_id", ad_id);
        con.Open();
        SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.SequentialAccess);
        if (reader.HasRows)
        {
            reader.Read();
            MemoryStream memory = new MemoryStream();
            long startIndex = 0;
            const int ChunkSize = 256;
            while (true)
            {
                byte[] buffer = new byte[ChunkSize];
                long retrievedBytes = reader.GetBytes(0, startIndex, buffer, 0, ChunkSize);
                memory.Write(buffer, 0, (int)retrievedBytes);
                startIndex += retrievedBytes;
                if (retrievedBytes != ChunkSize)
                    break;
            }

            byte[] data = memory.ToArray();
            memory.Dispose();
            image1.Src = "data:image/png;base64," + Convert.ToBase64String(data);
        }
        con.Close();
    }

How to do it...javascript ans is most welcome.
Posted
Updated 17-May-14 10:07am
v5
Comments
So, what is the issue in jQuery code?
Raj Negi 26-Apr-14 6:25am    
it is not working, nothing happens on click

 
Share this answer
 
ASP.NET
<img id="image1" runat="server" src="" alt="" height="100" width="100" onclick="ShowDialog1()"/>

<div id="dialog1" title="Full Image View" style="display: none">
<img id="Img1" runat="server" />
</div>

JavaScript
function ShowDialog1() {
            $("#dialog1").dialog();
        }

C#
protected void LoadImage1()
    {
        SqlCommand cmd = new SqlCommand("sps_getimage", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@flag", 1);
        cmd.Parameters.AddWithValue("@ad_id", ad_id);
        con.Open();
        SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.SequentialAccess);
        if (reader.HasRows)
        {
            reader.Read();
            MemoryStream memory = new MemoryStream();
            long startIndex = 0;
            const int ChunkSize = 256;
            while (true)
            {
                byte[] buffer = new byte[ChunkSize];
                long retrievedBytes = reader.GetBytes(0, startIndex, buffer, 0, ChunkSize);
                memory.Write(buffer, 0, (int)retrievedBytes);
                startIndex += retrievedBytes;
                if (retrievedBytes != ChunkSize)
                    break;
            }

            byte[] data = memory.ToArray();
            memory.Dispose();
            image1.Src = "data:image/png;base64," + Convert.ToBase64String(data);
            Img1.Src = "data:image/png;base64," + Convert.ToBase64String(data);
        }
        con.Close();
    }
 
Share this answer
 
Hey,
u can put your image in a datalist or loop through one image control four times.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900