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

Show image directly from database

1 Answer 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joffrey
Top achievements
Rank 2
Joffrey asked on 25 Aug 2008, 08:46 AM

Hi all

I have a Databasetable with images in it.
Now I want to show those images in a GridTemplateColumn.
I want to show them directly from database, without first storing the pics on disk.
Is this possible? And how?

The code so far looks like this:

<telerik:GridTemplateColumn UniqueName="ImageColumn">  
    <ItemTemplate> 
        <img id="PlantImage" src='<%# Eval("Image") %>.jpg' alt=""/>  
    </ItemTemplate> 
    <HeaderStyle Width="100px" /> 
    <ItemStyle Width="240px" /> 
</telerik:GridTemplateColumn> 

But the images wont show up in the Grid.
I'm just stuck.

Thanks for your help.
Joffrey


FYI, this is the code I use to upload the images into the database. They are uploaded with  radUpload. Code is mostly from a Telerik KB article.

protected void btnUpload_Click(object sender, EventArgs e)  
    {  
        mediaTypeTable = mediaType.GetAllMediaTypes();  
 
        foreach (UploadedFile file in ruplMedia.UploadedFiles)  
        {  
            string extension = file.GetExtension().Remove(0,1);  
            string imageType = file.ContentType;  
            string name = file.GetNameWithoutExtension();  
 
            //Set the mediaTypeId  
            int mediaTypeId = 0;  
            foreach (DataRow row in mediaTypeTable.Rows)  
            {  
                if (extension.Equals(row["Extension"].ToString()))  
                {  
                    mediaTypeId = Convert.ToInt32(row["MediaTypeId"]);  
                    break;  
                }  
            }  
 
            //ImageData  
            byte[] binaryImageData = new byte[file.InputStream.Length];  
            file.InputStream.Read(binaryImageData, 0, Convert.ToInt32(file.InputStream.Length));  
 
            media.Insert(Convert.ToInt32(rcbPlant.SelectedValue), mediaTypeId, name, name, binaryImageData);  
        }  
    } 

1 Answer, 1 is accepted

Sort by
0
Accepted
Yavor
Telerik team
answered on 27 Aug 2008, 11:43 AM
Hi Joffrey,

To see more information along the lines of the requested functionality, please refer to the following post. It also contains a working sample.
I hope this gets you started properly.

Regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Joffrey
Top achievements
Rank 2
Answers by
Yavor
Telerik team
Share this question
or