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

Export GridDateTimeColumn to pdf

4 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 15 Apr 2010, 08:47 AM
Hi,

we evaluate the RadGrid as our new standard Grid. Everytime I export my grid to pdf (csv, word and excel works well) I get this error:

System.InvalidCastException: Unable to cast object of type 'Telerik.Web.Apoc.Layout.BlockArea' to type 'Telerik.Web.Apoc.Layout.AreaContainer'. at Telerik.Web.Apoc.Fo.Flow.BlockContainer.Layout(Area area) at Telerik.Web.Apoc.Fo.Flow.Block.Layout(Area area) at Telerik.Web.Apoc.Fo.Flow.TableCell.Layout(Area area) at Telerik.Web.Apoc.Fo.Flow.TableRow.Layout(Area area) at Telerik.Web.Apoc.Fo.Flow.AbstractTableBody.Layout(Area area) at Telerik.Web.Apoc.Fo.Flow.Table.Layout(Area area) at Telerik.Web.Apoc.Fo.Flow.Block.Layout(Area area) at Telerik.Web.Apoc.Fo.Flow.Flow.Layout(Area area, Region region) at Telerik.Web.Apoc.Fo.Flow.Flow.Layout(Area area) at Telerik.Web.Apoc.Fo.Pagination.PageSequence.Format(AreaTree areaTree) at Telerik.Web.Apoc.StreamRenderer.Render(PageSequence pageSequence) at Telerik.Web.Apoc.Fo.FOTreeBuilder.EndElement() at Telerik.Web.Apoc.Fo.FOTreeBuilder.Parse(XmlReader reader)


I'm using the RadGrid the ASP.NET AJAX Q1 2010 version (Telerik.Web.UI Trial Version 2010.1.309.20).

Can anyone confirm my problem and suggest a solution?

Appreciate your help! Kind regards,
Michael
 
aspx:

<%

@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ExportGridDateTimeColumnError._Default" %>

 

<%

@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

 

<!

 

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<

 

html xmlns="http://www.w3.org/1999/xhtml" >

 

<

 

head runat="server">

 

 

<title>Untitled Page</title>

 

</

 

head>

 

<

 

body>

 

 

<form id="form1" runat="server">

 

 

<div>

 

 

 

<script type="text/javascript">

 

 

function onRequestStart(sender, args) {

 

 

if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||

 

args.get_eventTarget().indexOf(

"ExportToWordButton") >= 0 ||

 

args.get_eventTarget().indexOf(

"ExportToPdfButton") >= 0 ||

 

args.get_eventTarget().indexOf(

"ExportToCsvButton") >= 0) {

 

args.set_enableAjax(

false);

 

}

}

 

</script>

 

 

 

<telerik:RadScriptManager ID="RadScriptManager1" runat="server">

 

 

</telerik:RadScriptManager>

 

 

 

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" >

 

 

<ClientEvents OnRequestStart="onRequestStart" />

 

 

<AjaxSettings>

 

 

<telerik:AjaxSetting AjaxControlID="RadAjaxManager1">

 

 

<UpdatedControls>

 

 

<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"/>

 

 

</UpdatedControls>

 

 

</telerik:AjaxSetting>

 

 

<telerik:AjaxSetting AjaxControlID="RadGrid1">

 

 

<UpdatedControls>

 

 

<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />

 

 

</UpdatedControls>

 

 

</telerik:AjaxSetting>

 

 

</AjaxSettings>

 

 

</telerik:RadAjaxManager>

 

 

 

<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Vista">

 

 

</telerik:RadAjaxLoadingPanel>

 

 

 

<telerik:RadGrid ID="RadGrid1" runat="server" Width="1024px" Skin="Vista"

 

 

AllowSorting="true"

 

 

AllowFilteringByColumn="true"

 

 

AllowPaging="true" PageSize="10"

 

 

ShowHeader="true"

 

 

ShowFooter="true"

 

 

ShowGroupPanel="true"

 

 

OnItemCommand="RadGrid1_ItemCommand">

 

 

<ClientSettings ReorderColumnsOnClient="True" AllowDragToGroup="True" AllowColumnsReorder="True">

 

 

<Selecting AllowRowSelect="True"></Selecting>

 

 

<Resizing AllowRowResize="True" AllowColumnResize="True" EnableRealTimeResize="True" ResizeGridOnColumnResize="False"></Resizing>

 

 

</ClientSettings>

 

 

<GroupingSettings ShowUnGroupButton="true" />

 

 

<ExportSettings IgnorePaging="true" OpenInNewWindow="true">

 

 

<Pdf PageHeight="297mm" PageWidth="210mm" PageTitle="PDF Export Test" />

 

 

</ExportSettings>

 

 

 

<MasterTableView Width="80%" CommandItemDisplay="Top">

 

 

<PagerStyle Mode="NextPrevNumericAndAdvanced" />

 

 

<CommandItemSettings

 

 

ShowExportToWordButton="true"

 

 

ShowExportToExcelButton="true"

 

 

ShowExportToCsvButton="true"

 

 

ShowExportToPdfButton="true"

 

 

/>

 

 

</MasterTableView>

 

 

</telerik:RadGrid>

 

 

 

</div>

 

 

</form>

 

</

 

body>

 

</

 

html>

 


cs:

using

 

System;

 

using

 

System.Collections;

 

using

 

System.Configuration;

 

using

 

System.Data;

 

using

 

System.Linq;

 

using

 

System.Web;

 

using

 

System.Web.Security;

 

using

 

System.Web.UI;

 

using

 

System.Web.UI.HtmlControls;

 

using

 

System.Web.UI.WebControls;

 

using

 

System.Web.UI.WebControls.WebParts;

 

using

 

System.Xml.Linq;

 

namespace

 

ExportGridDateTimeColumnError

 

{

 

public partial class _Default : System.Web.UI.Page

 

{

 

protected void Page_Load(object sender, EventArgs e)

 

{

RadGrid1.DataSource = getDemoData();

}

 

public DataTable getDemoData()

 

{

 

DataTable dt = new DataTable();

 

 

DataColumn myDataColumn;

 

 

Random rnd = new Random();

 

myDataColumn =

new DataColumn();

 

myDataColumn.DataType =

Type.GetType("System.String");

 

myDataColumn.ColumnName =

"Guid";

 

dt.Columns.Add(myDataColumn);

myDataColumn =

new DataColumn();

 

myDataColumn.DataType =

Type.GetType("System.Int32");

 

myDataColumn.ColumnName =

"number";

 

dt.Columns.Add(myDataColumn);

myDataColumn =

new DataColumn();

 

myDataColumn.DataType =

Type.GetType("System.DateTime");

 

myDataColumn.ColumnName =

"date";

 

dt.Columns.Add(myDataColumn);

 

for (int i = 0; i < 1000; i++)

 

{

AddDataRowToTable(System.

Guid.NewGuid().ToString(), rnd.Next(), DateTime.Now, dt);

 

}

 

return dt;

 

}

 

private void AddDataRowToTable(string guid, int number, DateTime date, DataTable dataTable)

 

{

 

DataRow row;

 

row = dataTable.NewRow();

row[

"guid"] = guid;

 

row[

"number"] = number;

 

row[

"date"] = date;

 

dataTable.Rows.Add(row);

}

 

protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)

 

{

 

if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToExcelCommandName ||

 

e.CommandName == Telerik.Web.UI.

RadGrid.ExportToWordCommandName ||

 

e.CommandName == Telerik.Web.UI.

RadGrid.ExportToCsvCommandName ||

 

e.CommandName == Telerik.Web.UI.

RadGrid.ExportToPdfCommandName)

 

{

ConfigureExport();

}

}

 

public void ConfigureExport()

 

{

RadGrid1.ExportSettings.ExportOnlyData =

false;

 

RadGrid1.ExportSettings.IgnorePaging =

true;

 

RadGrid1.ExportSettings.OpenInNewWindow =

true;

 

}

}

}

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 19 Apr 2010, 03:56 PM
Hello Michael,

Please try to remove GridPagerItem and GridFilteringItem before export:
bool isExport = false;
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToExcelCommandName || e.CommandName == Telerik.Web.UI.RadGrid.ExportToWordCommandName || e.CommandName == Telerik.Web.UI.RadGrid.ExportToCsvCommandName || e.CommandName == Telerik.Web.UI.RadGrid.ExportToPdfCommandName)
    {
        isExport = true;
        ConfigureExport();
    }
}
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
if (isExport && (e.Item is GridPagerItem || e.Item is GridFilteringItem))
    e.Item.Visible = false;
}

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.
0
Michael
Top achievements
Rank 1
answered on 20 Apr 2010, 02:08 PM
Hi Daniel,

thanks a lot, it worked.

Kind regards,
Michael
0
Dimitri
Top achievements
Rank 1
answered on 11 Nov 2015, 09:41 AM
Thanks it works, but I muss yet to replace <br> to <br/>
0
Dimitri
Top achievements
Rank 1
answered on 11 Nov 2015, 09:42 AM
  protected void RadGrid1_PdfExporting(object sender, GridPdfExportingArgs e)
        {
            e.RawHTML = e.RawHTML.Replace("<br>", "<br/>");

        }
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Michael
Top achievements
Rank 1
Dimitri
Top achievements
Rank 1
Share this question
or