locked
Images not well displayed in Datalist control RRS feed

  • Question

  • Hi,
           can anyone solve my problem.

          i have 4 images  stored in my db and  i  have tried to populate the images to DataList control using the following code.
          protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    string imageid = Request.QueryString["id"];
                    if (imageid == null || imageid == "")
                    {
                       //Set a default imageID
                        imageid = "16";
                    }

                    SqlConnection connection = new SqlConnection("server=Everest;initial catalog=kk;uid=sa;pwd=kk");
                    connection.Open();
                    SqlCommand command = new SqlCommand("select Image from tblImage where id=" + imageid, connection);
                    SqlDataReader dr = command.ExecuteReader();
                    dr.Read();
                    Stream str = new MemoryStream((Byte[])dr["Image"]);
                   
                        Bitmap loBMP = new Bitmap(str);
                        Bitmap bmpOut = new Bitmap(100, 100);
                        Graphics g = Graphics.FromImage(bmpOut);
                        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                        g.FillRectangle(Brushes.White, 0, 0, 100, 100);
                        g.DrawImage(loBMP, 0, 0, 100, 100);
                        MemoryStream ms = new MemoryStream();
                        bmpOut.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                        byte[] bmpBytes = ms.GetBuffer();
                        bmpOut.Dispose();
                        ms.Close();
                        Response.BinaryWrite(bmpBytes);
                        connection.Close();
                        Response.End();
                   
                }
     
       }


           All images are displayed to datalist control but one or 2 images are not showing, the image sizes are as below

           Image1         1.26 kb
           Image2         4.00 kb
           Image3         550 kb
           Image4         459 kb      

         Image1 and Image2 were displayed well in DataList. but Image3 and Image4 were quarterly displayed, I need to displayed full Image
         How can i solve this problem.

         plz guide to me.

        thanks and regards
        brite
    • Moved by Aland Li Friday, February 19, 2010 2:54 AM Incorrect forum (From:Windows Forms Data Controls and Databinding)
    Friday, February 12, 2010 7:15 AM

Answers

  • Hi Britekumar,

    As far as I know, DataList is a control in Asp.Net. You need to post in one of the forum below:
    http://forums.asp.net/

    I am moving the thread to the 'Off-Topic' forum since the issue is not related to Windows Forms.

    Regards,
    Aland Li
    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    • Marked as answer by Britekumar Saturday, February 20, 2010 12:46 AM
    Monday, February 15, 2010 12:43 PM