PDF/RADGRID

9 posts, 1 answers
  1. Carlos
    Carlos avatar
    83 posts
    Member since:
    Apr 2013

    Posted 05 Jul 2013 Link to this post

    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

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

    Posted 05 Jul 2013 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Carlos
    Carlos avatar
    83 posts
    Member since:
    Apr 2013

    Posted 05 Jul 2013 Link to this post

    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.

  5. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 05 Jul 2013 Link to this post

    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
  6. Carlos
    Carlos avatar
    83 posts
    Member since:
    Apr 2013

    Posted 08 Jul 2013 Link to this post

    Thanks,

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

    thanks a lot
  7. Carlos
    Carlos avatar
    83 posts
    Member since:
    Apr 2013

    Posted 08 Jul 2013 Link to this post

    Hi,

    it worked fine until i put true on ignore paging now it doesnt do nothing, is it imcompatible with ignore pagin??
  8. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 09 Jul 2013 Link to this post

    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
  9. soumen
    soumen avatar
    5 posts
    Member since:
    Aug 2015

    Posted 05 Sep 2015 in reply to Jayesh Goyani Link to this post

    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 ? 

  10. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 08 Sep 2015 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017