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

Export to PDF is not working when Grid had Template Columns

6 Answers 524 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Karan
Top achievements
Rank 1
Karan asked on 31 Jan 2013, 12:15 AM
When a grid view has template columns with images and hyperlinks. The PDF export does not render these columns.
Is there a fix or work around for this bug ?


6 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 31 Jan 2013, 04:01 AM
Hello,

RadGrid1.ExportSettings.ExportOnlyData = false;
OR
<ExportSettings ExportOnlyData="false">
        </ExportSettings>




Thanks,
Jayesh Goyani
0
Karan
Top achievements
Rank 1
answered on 31 Jan 2013, 04:05 AM
Have tried that, it does not fix anything. Setting that flag to False allows Image to show in the Export PDF file, but even the Images are not rendered properly.


0
Jayesh Goyani
Top achievements
Rank 2
answered on 31 Jan 2013, 04:30 AM
Hello,

Please try with below code snippet.
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnItemCommand="RadGrid1_ItemCommand"
           OnNeedDataSource="RadGrid1_NeedDataSource" OnItemDataBound="RadGrid1_ItemDataBound">
           <ExportSettings ExportOnlyData="true">
           </ExportSettings>
           <MasterTableView Width="950" AutoGenerateColumns="false" DataKeyNames="ID" GridLines="None"
               CommandItemDisplay="Top">
               <CommandItemSettings ShowExportToPdfButton="true" />
               <Columns>
                   <telerik:GridBoundColumn DataField="ID" HeaderText="Emp ID" ReadOnly="true" HeaderStyle-HorizontalAlign="Left"
                       ItemStyle-HorizontalAlign="Left" UniqueName="ID" FilterControlWidth="30px" AutoPostBackOnFilter="true"
                       CurrentFilterFunction="Contains">
                   </telerik:GridBoundColumn>
                   <telerik:GridTemplateColumn UniqueName="Test">
                       <ItemTemplate>
                           <asp:Image ID="Image1" runat="server" AlternateText="test" />
                       </ItemTemplate>
                   </telerik:GridTemplateColumn>
               </Columns>
           </MasterTableView>
       </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
   {
       dynamic data = new[] {
            new { ID = 1, Name ="Name_1"},
              new { ID = 2, Name = "Name_2"},
              new { ID = 3, Name = "Name_3"},
              new { ID = 4, Name = "Name_4"},
              new { ID = 5, Name = "Name_5"}
       };
 
       RadGrid1.DataSource = data;
 
   }
 
 
   protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
 
   }
 
 
   protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
   {
       if (e.CommandName == RadGrid.ExportToPdfCommandName)
       {
           foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
           {
               item["Test"].Text = "<img src=\"http://www.w3schools.com/tags/smiley.gif\" alt=\"Smiley face\" />";
           }
       }
   }


Thanks,
Jayesh Goyani
0
Karan
Top achievements
Rank 1
answered on 06 Feb 2013, 03:44 AM
Hi Jayesh, Thanks for the reply.

Setting the "Text" property on the Item Command does not work for excel export.

I am doing the exact same things as your example but for excel. It is outputting blank cells in excel.

Please let me know how to fix it.

Thanks
0
Kostadin
Telerik team
answered on 08 Feb 2013, 02:32 PM
Hi Karan,

Note that the only Excel format which support image exporting is BIFF format. In order to work correctly you have to set ExportOnlyData to false. More information could be found at the following help article.

All the best,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
fsr
Top achievements
Rank 1
answered on 06 Jun 2018, 01:45 PM

Hello,

I'm not sure if I should make a new post or just ask here since this somewhat fits my problem. 

I'm using a RadGrid which is bound serverside to a list of 'StatisticObjects'. These Objects have properties which are shown in the grid at run time. Mostly my properties are text, but one property is a decimal which represents a percentage. I used an ItemTemplate to display a RadProgressBar like this:

<telerik:GridTemplateColumn DataField="Procentual" Exportable="true" ReadOnly="true">
   <ItemTemplate>
      <telerik:RadProgressBar runat="server" BarType="Percent" MinValue="0" MaxValue="1" Width="100%" Value='<%# Eval("Procentual") %>'></telerik:RadProgressBar>
      </ItemTemplate>
</telerik:GridTemplateColumn>

So here comes the problem: If i export this in excel it works just fine and i get the value of my given object. However if I export to PDF my cells for this columns are just empty.

I already tried:

  • setting the ExportSettings to ExportOnlyData = true;
  • adding an invisible lable with the same value (didn't even work visible)
  • changing datatype from double to float/decimal
Tags
Grid
Asked by
Karan
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Karan
Top achievements
Rank 1
Kostadin
Telerik team
fsr
Top achievements
Rank 1
Share this question
or