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

Image in RadGrid Column

1 Answer 1090 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 24 Sep 2015, 08:39 PM

I am trying to use a datatable as a radgrid source and display an image in the cell.  I have followed this example (Displaying Images in a GridView Column), but it just displays the URL string instead of the image.  In searching for a solution many people have this same problem.  I have tried other things, but they too do not work.   

If I use RadGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) and the first code section below it works.  Unfortunately that brings up another problem.  I also use ToggleRowSelection(object sender, EventArgs e) and this removes the image when it is called.  I could possibly call RadGrid_ItemDataBound from ToggleRowSelection, but one has EventArgs and the other has Telerik.Web.UI.GridItemEventArgs and casting does not work. There may be a better way to get  RadGrid_ItemDataBound to fire after ToggleRowSelection, but I would like to be able to put the image in initially if possible.    

RadGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)

...

Image imgTrue = new Image();
imgTrue.ImageUrl = "images/true.png";
item["Picture"].Controls.Add(imgTrue);

 

Here is my code from the linked example.  images/false.png appears instead on the image.    

DataTable oDT = new DataTable();
//oDT.Columns.Add("Picture");
oDT.Columns.Add(New DataColumn("Picture", GetType(String));
DataRow myRow = oDT.NewRow();
myRow["Picture"].ResolveUrl("images/false.png");
 
oDT.Rows.Add(myRow);
 
DataSet MyDataSet1 = new DataSet("pic");
MyDataSet1.Tables.Add(oDT); 
 
RadGrid1.DataSource = MyDataSet1;
RadGrid1.DataBind();

 

1 Answer, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 29 Sep 2015, 08:32 PM
Hello,

You can refer to the following link for a sample code:
http://stackoverflow.com/questions/12987304/showing-image-in-radgrid-using-datatable

Additionally, I recommend you populate the grid inside NeedDataSource as demonstrated in the article below:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-binding/understanding-data-binding/server-side-binding/various-data-sources/binding-to-datatable-or-dataset

Regards,
Pavlina
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Scott
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or