Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8390581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:01:52+00:00 2026-06-09T19:01:52+00:00

I have a little problem here. On my page I use a asp:repeater to

  • 0

I have a little problem here.

On my page I use a asp:repeater to read out all the “Projects” from my database.
Now each project also contains two images (binary data) and I want to convert them back to images in a handler and use the handler file as the image reference.

I found this code on the web, I also know how it wokrs but I dont know how to use in with a handler:

public Byte[] Ret_image(Int32 id)
{
    SqlCommand cmd = new SqlCommand();
    cmd.CommandText = "SELECT * FROM Project where Id=@id";
    cmd.Connection = con;
    cmd.Parameters.Add("@id", SqlDbType.Int).Value = id;
    SqlDataReader dr = cmd.ExecuteReader();
    dr.Read();
    Byte[] ar = (Byte[])(dr[1]);
    dr.Close();
    cmd.Dispose();
    return ar;
}

I think this would probably work, all I need to do I think is to give the ID of each project, but I don’t quite know how to implement this and I don’t even know if the code above is correct.

Can anyone help me?

thanks in advance!

[edit]

How do I give the handler the IDs it needs?

<asp:Image ID="img" ImageUrl="Image.ashx" runat="server" Height="80" Width="75%" />

Or how can I get the correct IDs from within the handler?

[EDIT 2]

What am I doing wrong? The Images do not appear, But it doesn’t say that it doesn’t find them:

<asp:img class="icon-img icon-img_shadow" src="Image.ashx?ID=<%# DataBinder.Eval(Container, "DataItem.id") %>" alt="Icon" width="152" height="140" />

Code in handler:

public void ProcessRequest (HttpContext context) {
    int id = Convert.ToInt32(context.Request.QueryString["ID"]);

    context.Response.ContentType = "image/png";
    MemoryStream strm = new MemoryStream(Ret_image(id));
    byte[] buffer = new byte[4096];
    int byteSeq = strm.Read(buffer, 0, 4096);
    while (byteSeq > 0)
    {
        context.Response.OutputStream.Write(buffer, 0, byteSeq);
        byteSeq = strm.Read(buffer, 0, 4096);
    }
}

public Byte[] Ret_image(Int32 id)
{
    SqlConnection sqlCn = new SqlConnection("Data Source=server;Initial Catalog=db;User ID=user;Password=pw");

    string qry = "SELECT * FROM Project WHERE imageid=@id";
    SqlCommand cmd = new SqlCommand(qry, sqlCn);
    cmd.Parameters.Add("@id", SqlDbType.Int).Value = id;
    SqlDataReader dr = cmd.ExecuteReader();
    sqlCn.Open();
    dr.Read();
    Byte[] ar = (Byte[])(dr[1]);
    dr.Close();
    cmd.Dispose();
    sqlCn.Close();
    return ar;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:01:54+00:00Added an answer on June 9, 2026 at 7:01 pm

    You need to create an ashx page that you’ll target as an image URL

    Then you need to write the byte array as response stream in the ProcessRequest method inside that handler… Something like:

    context.Response.ContentType = "image/jpeg";
    strm = new MemoryStream(ar);   // ar here is your variable from Byte[] ar = (Byte[])(dr[1])
    byte[] buffer = new byte[4096];
    int byteSeq = strm.Read(buffer, 0, 4096);
    while (byteSeq > 0)
    {
        context.Response.OutputStream.Write(buffer, 0, byteSeq);
        byteSeq = strm.Read(buffer, 0, 4096);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem with Jquery getJSON function. my json here { entries:
I have a little problem with javascript form submit issue, here is the script
I need a little push in the right direction. Here's my problem: I have
I have a litte problem here. I want to join twice from the same
I've got a real problem here. I have a page at: [page removed] and
I have a problem with page rendering after migration from WAS 6.0 + JSF
I have built a little crawler and now when trying it out i found
I'm new around here and i have a little problems with a C# application.
I have little problem with a replacement of a little part in an url.
I have little problem in regular expressin creation. Expected input: blahblahblah, blahblahblah, 'blahblahblah', blahblahblah,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.