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

PDF/RADGRID

8 Answers 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carlos
Top achievements
Rank 1
Carlos asked on 05 Jul 2013, 01:08 PM
Hi all,

i having this error:

Telerik.Web.UI.Grid.Export.GridPdfExportException: Invalid XHTML. RadGrid has to render correct XHTML in order to export to PDF.
Parse error:
Name cannot begin with the '<' character, hexadecimal value 0x3C. Line 750, position 144.
at line:
<td>6</td><td>2012/12/06 01:07</td><td>KT0001</td><td>&nbsp;</td><td>CASHBOX</td><td>WARNING</td><td>Coffins: Total Amount: >265910<</td><td>Coprses:123456789</td>

the is simple, i activated the pdf export and the radgrid i inserted and made a databind on the codebehind only that.

Best Regards

8 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 05 Jul 2013, 01:16 PM
Hello,

Please try with the below code snippet.

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
    OnItemCommand="RadGrid1_ItemCommand">
    <MasterTableView CommandItemDisplay="Top">
        <CommandItemSettings ShowExportToPdfButton="true" />
        <Columns>
            <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    dynamic data = new[] {
        new { ID = 1, Name ="Nam<>e1"},
        new { ID = 2, Name = "Name2"},
        new { ID = 3, Name = "Name3"},
         new { ID = 4, Name = "Name4"},
        new { ID = 5, Name = "Name5"}
    };
 
    RadGrid1.DataSource = data;
 
}
 
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
 
    if (e.CommandName == RadGrid.ExportToPdfCommandName)
    {
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
        {
            item["Name"].Text = item["Name"].Text.Replace("<", "&lt;").Replace(">", "&gt;");
        }
    }
}



Thanks,
Jayesh Goyani
0
Carlos
Top achievements
Rank 1
answered on 05 Jul 2013, 02:24 PM
i Know that would work i i had acess to the name of the columns, but i dont have the grid is made automatacly i dont have control of the columns.

and im trying to convert the code to use columns bu im not getting luck.

0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 06 Jul 2013, 04:11 AM
Hello,

Please try with the below code snippet.

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
 
    if (e.CommandName == RadGrid.ExportToPdfCommandName)
    {
        foreach (GridColumn column in RadGrid1.MasterTableView.Columns)
        {
            //foreach(GridColumn column in RadGrid1.MasterTableView.AutoGenerateColumns) // If column generated Automatically
 
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
            {
                item[column.UniqueName].Text = item[column.UniqueName].Text.Replace("<", "&lt;").Replace(">", "&gt;");
            }
        }
    }
}


Thanks,
Jayesh Goyani
0
Carlos
Top achievements
Rank 1
answered on 08 Jul 2013, 11:08 AM
Thanks,

it Was autogenerated columns, and not autogenerate,
but it was that

thanks a lot
0
Carlos
Top achievements
Rank 1
answered on 08 Jul 2013, 03:48 PM
Hi,

it worked fine until i put true on ignore paging now it doesnt do nothing, is it imcompatible with ignore pagin??
0
Jayesh Goyani
Top achievements
Rank 2
answered on 09 Jul 2013, 06:00 AM
Hello,

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
 
    if (e.CommandName == RadGrid.ExportToPdfCommandName)
    {
        RadGrid1.AllowPaging = false;
        RadGrid1.Rebind();
        foreach (GridColumn column in RadGrid1.MasterTableView.Columns)
        {
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
            {
                item[column.UniqueName].Text = item[column.UniqueName].Text.Replace("<", "&lt;").Replace(">", "&gt;");
            }
        }
    }
}



Thanks,
Jayesh Goyani
0
soumen
Top achievements
Rank 1
answered on 05 Sep 2015, 12:38 PM

Hi All,

When the grid is exported in pdf then exported file contains "&gt;","&lt;"(Encoded HTML) instead of ">","<".How do i ​solve this problem ? 

0
Eyup
Telerik team
answered on 08 Sep 2015, 02:10 PM
Hi Soumen,

I've already replied to your query in the following forum:
http://www.telerik.com/forums/pdf-export-fails-with-special-characters-in-data

I suggest that we continue our conversation on the mentioned thread.

Regards,
Eyup
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Carlos
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Carlos
Top achievements
Rank 1
soumen
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or