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

[Solved] Displaying BinaryImage from sql db in grid

2 Answers 355 Views
Grid
This is a migrated thread and some comments may be shown as answers.
reynald lawrence
Top achievements
Rank 1
reynald lawrence asked on 27 Jul 2009, 02:28 PM
Hi! I have a grid which has binaryimagecolumn which binds data in sql db. My problem is I still can't display the image correctly in the grid, even if the object which corresponds into the binaryimagecolumn has a byte[] type in c# and image type in sql database.

markup:

<

 

telerik:GridBinaryImageColumn DataField="PictureImg" HeaderText="Image" UniqueName="PictureImg"

 

 

ImageAlign="Middle" ImageHeight="200px" ImageWidth="200px" ResizeMode="Fit">

 

 

<HeaderStyle Width="10%" />

codebehind:

 

 

protected class PictureTemplate

 

 

 

 

{

 

public Guid PictureID { get; set; }

 

 

public string PictureName { get; set; }

 

 

public byte[] PictureImg { get; set; }

 

 

public string PictureDesc { get; set; }

 

}


 

protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)

 

{

 

List<PictureTemplate> picTemplate;

 

 

using (DianaOnlinePhotoEntities db = new DianaOnlinePhotoEntities())

 

{

picTemplate = (

from p in db.tblPicture

 

 

where p.PictureID != null

 

 

select new PictureTemplate

 

{

PictureID = p.PictureID,

PictureName = p.PictureName,

PictureImg = p.PictureImg,

PictureDesc = p.PictureDesc

}).ToList();

RadGrid1.DataSource = picTemplate;

}

}



Hope I can fix the problem, Thanks!!

2 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 30 Jul 2009, 10:16 AM
Hello reynald,

If all of your columns display data correctly, except for the GridBinaryImageColumn, the problem might originate if you have not registered an HTTP handler for the control.

RadBinaryImage and its implementation in the GridBinaryImageColumn, as well as some other RadControls require an HTTP handler to be registered in web.config that they use for data retrieval purposes. If you use  RadScriptManager on your page, instead of the standard ASP.NET ScriptManager control, you know that you need to register an HTTP handler for RadScriptManager. RadBinaryImage can use the same HTTP handler.

In a few words, you can either use RadScriptManager and its HTTP handler, or register the HTTP handler only (without the need to use RadScriptManager), as described in the following help article:

RadScriptManager

Regards,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
reynald lawrence
Top achievements
Rank 1
answered on 30 Jul 2009, 02:48 PM
Hi Veli,

My grid is displaying the images properly now, I followed ur advice then just replaced my regular Ajax ScriptManager control to RADScriptManager control then register it in the web.config.

I appreciate the solution and Thanks for your help.

Regards,
reynald
Tags
Grid
Asked by
reynald lawrence
Top achievements
Rank 1
Answers by
Veli
Telerik team
reynald lawrence
Top achievements
Rank 1
Share this question
or