This is a migrated thread and some comments may be shown as answers.

How to load an image to Gridview from .net Datatable

2 Answers 172 Views
GridView
This is a migrated thread and some comments may be shown as answers.
abhijith
Top achievements
Rank 1
abhijith asked on 14 Jul 2010, 04:55 PM
How can we load an image from SQL database (image stored as byte array) in image colum of gridview.
the grid binding is done through the .net datatable. Is it possible in this manner? if it is possible can i get a code sample...

thanx in advance...

expecting your valuable reply...

Regards
Abhijith

2 Answers, 1 is accepted

Sort by
0
Ваня
Top achievements
Rank 1
answered on 14 Jul 2010, 05:52 PM
0
Ahmet Özgür
Top achievements
Rank 1
answered on 21 Jul 2010, 01:57 PM
Hi,
can check this too
<telerik:GridViewImageColumn DataMemberBinding="{Binding OrijinalImage,Converter={StaticResource imgConverter}}" Header="Resim" ImageHeight="100" ImageWidth="100"/>
public class ImageConverter : IValueConverter
    {
        object IValueConverter.Convert(object value,
            Type targetType,
            object parameter,
            System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                Binary bin = value as Binary;
                byte[] bytes = bin.ToArray();
 
                MemoryStream stream = new MemoryStream(bytes);
 
                BitmapImage image = new BitmapImage();
                image.BeginInit();
                image.StreamSource = stream;
                image.EndInit();
 
 
                return image;
            }
 
            return null;
        }
 
        object IValueConverter.ConvertBack(object value,
            Type targetType,
            object parameter,
            System.Globalization.CultureInfo culture)
        {
            BitmapImage bitmapImage = value as BitmapImage;
            MemoryStream stream = new MemoryStream();
            byte[] bytes = null;
            Binary bin = null;
 
            bitmapImage.StreamSource.Read(bytes, 0, (int)bitmapImage.StreamSource.Length);
            bin = new Binary(bytes);
 
            return bin;
        }
Tags
GridView
Asked by
abhijith
Top achievements
Rank 1
Answers by
Ваня
Top achievements
Rank 1
Ahmet Özgür
Top achievements
Rank 1
Share this question
or