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 864423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:28:31+00:00 2026-05-15T09:28:31+00:00

i am trying to load images from the northwind database (categories table, images that

  • 0

i am trying to load images from the northwind database (categories table, images that are stored in the database) into grid view control. But it dosenot seems to work. Plz! have a look…

Default.aspx

    <asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
        AutoGenerateColumns="False" DataKeyNames="CategoryID" 
        DataSourceID="NorthWindSQLExpressConnectionString" 
        EnableModelValidation="True">
        <Columns>
            <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" 
                InsertVisible="False" ReadOnly="True" SortExpression="CategoryID" />
            <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" 
                SortExpression="CategoryName" />
            <asp:BoundField DataField="Description" HeaderText="Description" 
                SortExpression="Description" />
            <asp:TemplateField HeaderText="Picture" SortExpression="Picture">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Picture") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Image ID="Image1" runat="server" ImageUrl='<%# RetriveImage(Eval("CategoryID")) %>' />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="NorthWindSQLExpressConnectionString" runat="server" 
        ConnectionString="<%$ ConnectionStrings:NorthwindSQLExpressConnectionString %>" 
        SelectCommand="SELECT [CategoryID], [CategoryName], [Description], [Picture] FROM [Categories]">
    </asp:SqlDataSource>

</div>
</form>

[Partial] Default.aspx.cs

    protected string RetriveImage(object eval)
    {
        return ("ImageHandler.ashx?CategoryID=" + eval.ToString());
    }

[Partial] ImageHandler.ashx

    public void ProcessRequest(HttpContext context)
    {
        if (context.Request.QueryString == null)
        {
        }
        else
        {
            try
            {
                using (var sqlCon = new SqlConnection(conString))
                {
                    const string cmdString =
                        "Select picture from Categories where CategoryID=@CategoryID";
                    using (var sqlCmd = new SqlCommand(cmdString, sqlCon))
                    {
                        sqlCmd.Parameters.AddWithValue("@CategoryID", context.Request.QueryString["CategoryID"]);
                        string trmp = sqlCmd.ToString();
                        sqlCon.Open();
                        using (var sqlDr = sqlCmd.ExecuteReader())
                        {
                            sqlDr.Read();
                            context.Response.ContentType = "image/bmp"; //Added after "Ed B" Sugetion but still dosenot work :(
                            context.Response.BinaryWrite((byte[])sqlDr["Picture"]);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                context.Response.Write(ex.Message);
            }
        }
    }
  • 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-05-15T09:28:32+00:00Added an answer on May 15, 2026 at 9:28 am

    You need to set the content type in the generic handler

    context.Response.ContentType = "image/bmp";
    

    Hmm..try opening the handler with querystring inputs, directly from your browser…does that work?

    http://yourlocalhost/yourproject/ImageHandler.ashx?CategoryID=2

    You should see an error message if it fails.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to load images from a relative folder /media/one.jpg but it never loads,
I am trying to load images from the Facebook graph api into a div
I'm trying to load profile images (friend images) from Facebook with AS3 but I
I am trying to load three different images from an array into corresponding cells
I am am trying to load a SQL table from a flat file. The
I am trying to load an xml file that is stored as a resource
Using javascript I'm trying to load images not on the current page (from an
hello i am trying to load images from files in the start of my
I'm trying to load images (pdfs and Word documents) from a memory stream so
I am trying to load a list of images from an array. I got

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.