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

Pdf Export autogenerate columns image

1 Answer 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kai-Uwe
Top achievements
Rank 1
Kai-Uwe asked on 06 Oct 2010, 10:52 AM
Hi,

I have a grid with autogenerate columns set to true.

In ItemDataBound I add an image to a cell.

protected

 

 

void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)

 

{

 

 

if (this.reportProvider.HtmParams.ImageColumns.IsConfigColumn("TargetMet"))

 

{

 

 

if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)

 

{

 

 

if (e.Item.DataItem != null)

 

{

 

 

DataRowView row = (DataRowView)e.Item.DataItem;

 

 

 

string sImg = ImageColumnHandler.GetImage(ImageColumnHandler.KPI_TARGET, System.Convert.ToDouble(row["TargetMet"]));

 

 

 

Image img = new Image();

 

img.ImageUrl =

 

this.Request.ApplicationPath + "/Images/" + sImg;

 

 

 

GridDataItem item = (GridDataItem)e.Item;

 

 

 

TableCell cell = item["TargetMet"];

 

cell.Controls.Clear();

cell.Controls.Add(img);

}

}

}

 

 

}

 

 

 

 

 

 

In Html it looks just wonderfull.
Pdf export fails to display the image. It just shows the value from the datasource.

How can I add images in codebehind to a RadGrid with autogenerate columns set to true in a way it is safe for pdf export?

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 11 Oct 2010, 03:34 PM
Hello Kai-Uwe,

There are two possible issues:

1) RadGrid should rebind before export otherwise the code in the ItemDataBound handler won't execute. Please make sure that you either set IgnorePaging="true" or rebind it manually beforehand.
2) The path to the image should begin with tilde (~). Request.ApplicationPath will return something like this: /website

Best regards,
Daniel
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Kai-Uwe
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or