Export to PDF is not working when Grid had Template Columns

7 posts, 0 answers
  1. Karan
    Karan avatar
    14 posts
    Member since:
    Feb 2008

    Posted 30 Jan 2013 Link to this post

    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 ?


  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 30 Jan 2013 Link to this post

    Hello,

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




    Thanks,
    Jayesh Goyani
  3. Karan
    Karan avatar
    14 posts
    Member since:
    Feb 2008

    Posted 30 Jan 2013 Link to this post

    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.


  4. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 30 Jan 2013 Link to this post

    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
  5. Karan
    Karan avatar
    14 posts
    Member since:
    Feb 2008

    Posted 05 Feb 2013 Link to this post

    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
  6. Kostadin
    Admin
    Kostadin avatar
    1733 posts

    Posted 08 Feb 2013 Link to this post

    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.
  7. fsr
    fsr avatar
    1 posts
    Member since:
    Jun 2018

    Posted 06 Jun 2018 Link to this post

    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
Back to Top