Solved

how to add an image(.gif) to a datatable cell.

Posted on 2006-11-27
3
360 Views
Last Modified: 2012-08-13
my datatable column is

      dt5.Columns.Add(new DataColumn("Availability", typeof(Byte[])));

i am performing the following check
if(available==false)
                        {
                              img1.ImageUrl="";
                              img1.ImageUrl="green.gif";
                              DRC[j][1]=img1;

// i am gettin error in the above line.(i.e DRC[j][1]=img1)

                        }
0
Comment
Question by:poogie22
3 Comments
 
LVL 9

Expert Comment

by:peterdungan
ID: 18018048
You probably need to store a string in DRC[j][1] rather than an image object.
0
 
LVL 5

Accepted Solution

by:
Collindsouza earned 500 total points
ID: 18018081
or you can do it the following way...

here is an example

            //init
            dataGridView1.AutoGenerateColumns = false;
            DataTable dt = new DataTable();
            Bitmap bmp = new Bitmap("test.bmp");            

            //bitmap to byte[] and to datatable
            MemoryStream ms = new MemoryStream();
            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
            byte[] buf = ms.ToArray();
           
            //bind            
            dt.Columns.Add("Pic", typeof(Byte[]));
            dt.Rows.Add(buf);
            DataGridViewImageColumn cl = new DataGridViewImageColumn();
            cl.DataPropertyName = "Pic";
            dataGridView1.Columns.Add(cl);
            dataGridView1.DataSource = dt;
0
 
LVL 5

Expert Comment

by:prajapati84
ID: 18026819
Try this one, Some improvement to Collindsouza's code...

dt5.Columns.Add(new DataColumn("Availability", typeof(Byte[])));

if(available==false)
{
     img1.ImageUrl="green.gif";
     Bitmap bmp = new Bitmap("green.gif");
     System.IO.MemoryStream ms = new System.IO.MemoryStream();
     Picture_Employee.Image.Save(ms, Picture_Employee.Image.RawFormat);
     byte[] arrImage = ms.GetBuffer;
     ms.Close();
     DRC[j][1]=arrImage;
}

Regards,
Mukesh
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question