I'm trying to export a radgrid to a pdf with pictures that are embedded inside of it. I currently have a radgrid, and one of the columns is using a grid template column with a radlistview control, and a binary image control inside of that. Everything renders ok, but the pdfexport won't seem to export images. My goal with the grid template column is to load a list of photo's in each cell, but also be able to export this to a pdf.
protected void QuesGrd_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
using (var db = new IASurvey.Core.IADbContext())
{
GridDataItem item = (GridDataItem)e.Item;
Guid AnswerId = Guid.Parse(item["ansId"].Text);
HyperLink link = (HyperLink)item["link"].Controls[0];
var answerphoto = db.Photos.Where(p => p.PhotoAnswerId == AnswerId);
var answerlist = answerphoto.ToList();
RadListView lv = item.FindControl("RadListView1") as RadListView;
if (lv != null)
{
lv.DataSource = answerlist;
}
if (answerphoto.Any())
{
link.Text = "View/Print Photo(s)";
string url = "~/PhotoOpen.aspx?AnswerId=" + AnswerId;
link.Target = "_blank";
link.NavigateUrl = (url);
//link.Attributes.Add("onclick", "javascript:window.resizeTo(600,600);");
}
else
{
link.Text = "No Photos";
}
}
}
}
protected void QuesGrid_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.ExportToPdfCommandName)
{
foreach (GridHeaderItem item in QuesGrid.MasterTableView.GetItems(GridItemType.Header))
{
item.Style["font-size"] = "15pt";
foreach (TableCell cell in item.Cells)
{
cell.Style["font-size"] = "6pt";
cell.Style["vertical-align"] = "middle";
}
}
isPdfExport = true;
ConfigureExport();
}
}
protected void QuesGrid_ItemCreated(object sender, GridItemEventArgs e)
{
if (isPdfExport && e.Item is GridHeaderItem)
{
GridHeaderItem headerItem = (GridHeaderItem)e.Item;
headerItem.Style["font-size"] = "16pt";
headerItem.Style["color"] = "#ffffff";
headerItem.Style["background-color"] = "#BD0034";
headerItem.Style["height"] = "40px";
headerItem.Style["horizontal-align"] = "center";
headerItem.Style["vertical-align"] = "middle";
headerItem.Style["font-weight"] = "bold";
headerItem.Style["text-align"] = "center";
foreach (TableCell cell in headerItem.Cells)
{
}
}
}
public void ConfigureExport()
{
QuesGrid.ExportSettings.IgnorePaging = true;
QuesGrid.ExportSettings.ExportOnlyData = true;
QuesGrid.ExportSettings.OpenInNewWindow = true;
QuesGrid.ExportSettings.UseItemStyles = true;
QuesGrid.ClientSettings.Scrolling.AllowScroll = false;
QuesGrid.ExportSettings.FileName = "Survey (" + DateTime.Now + ")";
}
<
telerik:GridTemplateColumn
UniqueName
=
"photo"
HeaderText
=
"Photo(s)"
>
<
ItemTemplate
>
<
telerik:RadListView
ID
=
"RadListView1"
runat
=
"server"
DataMember
=
"Binary"
GroupItemCount
=
"10"
PageSize
=
"10"
>
<
ItemTemplate
>
<
telerik:RadBinaryImage
ID
=
"RadBinaryImage1"
runat
=
"server"
DataValue='<%#Eval("Image") %>' Width="200px" Height="200px" ResizeMode="Fit" />
<
p
class
=
"pagebreakhere"
>
</
ItemTemplate
>
</
telerik:RadListView
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>