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

Export to PDF with no data

6 Answers 177 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Raul
Top achievements
Rank 1
Raul asked on 28 Jan 2009, 12:14 PM
Hi all,

I have designed a rad grid and I want to export data within grid,
I have put 2 image buttons above grid 1 to export in excel formatr and other for PDF, excel button export data and no problem with it, but PDF button when click on, it shows PDF with the format I have customized but no data exported inside, and this code of this button:
<asp:ImageButton ID="ImageButton1" runat="server" AlternateText="Export to PDF"   
                                            ImageUrl="~/App_Data/Pdf.png" onclick="ImageButton1_Click"   
                                            CommandName="ExportToPdf" /> 

and I have handeled action oe this button as following:
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)  
        {  
            ConfigureExport();  
            RadGrid1.MasterTableView.ExportToExcel();  
        } 

but no data appears inside PDF.
Any one can help??

Regards

6 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 28 Jan 2009, 12:48 PM
Hello Raul,

It would be helpful if you share your code with us. In this way we will be able to assist you further.

Kind regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Raul
Top achievements
Rank 1
answered on 28 Jan 2009, 01:53 PM
Hi all,

My aspx and cs for this part is:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="projectrptexport.aspx.cs" Inherits="FireBall.forms.projects.projectrptexport" %> 
<%@ Register assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI" tagprefix="asp" %> 
 
<%@ Register assembly="dotnetCHARTING" namespace="dotnetCHARTING" tagprefix="dotnetCHARTING" %> 
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
 
<%@ Register assembly="Infragistics35.WebUI.UltraWebTab.v8.2, Version=8.2.20082.1000, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.WebUI.UltraWebTab" tagprefix="igtab" %> 
<%@ Register assembly="Infragistics35.WebUI.WebHtmlEditor.v8.2, Version=8.2.20082.1000, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.WebUI.WebHtmlEditor" tagprefix="ighedit" %> 
 
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %> 
 
<!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 id="Head1" runat="server">  
    <title>Projects module</title> 
      
   <link href="../../CSS/account_new-vfl67899.css" rel="stylesheet" type="text/css" /> 
    <link href="../../CSS/address_book-vfl69326.css" rel="stylesheet" type="text/css" /> 
    <link href="../../CSS/base_all-vfl70436.css" rel="stylesheet" type="text/css" /> 
    <link href="../../CSS/projects.css" rel="stylesheet" type="text/css" /> 
    <link href="../../CSS/MainSheet.css" rel="stylesheet" type="text/css" /> 
      
    <style type="text/css">  
        .style2  
        {  
        }  
              
.RadGrid_Vista  
{  
    font:11px/14px "segoe ui",arial,sans-serif;  
}  
 
.RadGrid_Vista  
{  
    border:1px solid #a7bac5;  
    background:#fcfcfc;  
    color:#333;  
}  
 
.MasterTable_Vista  
{  
    border-collapse:separate !important;  
}  
 
.MasterTable_Vista  
{  
    font:11px/14px "segoe ui",arial,sans-serif;  
}  
 
    </style> 
 
    <script type="text/javascript" id="igClientScript">  
<!--  
 
function RowDblClick(sender, eventArgs)  
         {  
         var x = eventArgs.getDataKeyValue("id");  
         window.location="newproj.aspx?projectID="+x;  
         }  
// --> 
</script> 
</head> 
<body> 
    <form id="form1" runat="server">  
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server">  
    </telerik:RadStyleSheetManager> 
    <telerik:RadScriptManager ID="ScriptManager1" runat="server"   
        EnableTheming="True">  
    </telerik:RadScriptManager> 
    <div> 
      <br /> 
       
           <table width="100%" align="center">  
             
            <tr align="center">  
                <td align="center">  
                 <fieldset style="width:97%;">  
                    <legend class="boldHeader">Projects report</legend> 
                      
                        <table width="100%" align="center">  
                            <tr align="center">  
                                <td align="center">  
                                    <div style="width: 100%" align="left">  
                                        <br /> 
                                                                                <asp:Button ID="Button1" runat="server"   
                                            CssClass="Imagebtn" onclick="Button1_Click" Text="Print to excel" onmouseover="this.className='ImagebtnHover'"   
                                onmouseout="this.className='Imagebtn'" Height="27px" Width="127px"/>&nbsp;  
&nbsp;<asp:Button ID="Button2" runat="server" CssClass="Imagebtn" onclick="Button2_Click" Text="Print to PDF" onmouseover="this.className='ImagebtnHover'"   
                                onmouseout="this.className='Imagebtn'" Height="27px" Width="104px"/>&nbsp;  
                                        <asp:DropDownList ID="paperSizeList" runat="server" AutoPostBack="true"   
                                            Height="20px" Width="132px">  
        </asp:DropDownList> 
                                        <br /> 
                                    </div> 
                                </td> 
                            </tr> 
                        </table> 
                     <asp:UpdatePanel ID="UpdatePanel1" runat="server">  
                        <ContentTemplate> 
                            <table style="width:100%;">  
                                <tr> 
                                    <td align="center" class="style2">  
                                        &nbsp;</td> 
                                </tr> 
                                <tr> 
                                    <td align="center" class="style2">  
                                        <telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True"   
                                            AllowAutomaticInserts="True" AllowAutomaticUpdates="True"   
                                            AllowMultiRowSelection="True" AllowPaging="True" AllowSorting="True"   
                                            AutoGenerateColumns="False" BorderWidth="1px" DataSourceID="SqlDataSource1"   
                                            GridLines="Vertical" onitemcreated="RadGrid1_ItemCreated"   
                                            ShowFooter="True" Skin="Gray" onitemcommand="RadGrid1_ItemCommand"   
                                            Height="185px">  
                                            <ExportSettings IgnorePaging="true" OpenInNewWindow="true">  
                <Pdf AllowAdd="false" AllowCopy="true" AllowModify="true" AllowPrinting="true" Author="Anonymous" 
                    Keywords="None" PageBottomMargin="1in" PageLeftMargin="1in" PageRightMargin="1in" PageTopMargin="1in" PageTitle="Data export document" 
                    Subject="Data Export" Title="Data export" PaperSize="Letter" /> 
            </ExportSettings> 
 
                                            <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"   
                                                Font-Strikeout="False" Font-Underline="False" Wrap="True" /> 
                                            <mastertableview clientdatakeynames="id" datakeynames="ID"   
                                                datasourceid="SqlDataSource1">  
                                                <rowindicatorcolumn> 
                                                    <HeaderStyle Width="20px" /> 
                                                </rowindicatorcolumn> 
                                                <expandcollapsecolumn> 
                                                    <HeaderStyle Width="20px" /> 
                                                </expandcollapsecolumn> 
                                                <Columns> 
                                                    <telerik:GridTemplateColumn UniqueName="TemplateColumn">  
                                                        <EditItemTemplate> 
                                                            <table style="width:100%;">  
                                                                <tr> 
                                                                    <td> 
                                                                        <asp:Label ID="Label15" runat="server" Text='<%# Eval("ID") %>'></asp:Label> 
                                                                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Subject") %>'></asp:TextBox> 
                                                                    </td> 
                                                                </tr> 
                                                            </table> 
                                                        </EditItemTemplate> 
                                                        <HeaderTemplate> 
                                                            <table style="width:100%;">  
                                                                <tr> 
                                                                    <td colspan="8" align="left">  
                                                                        <asp:Image ID="Image1" runat="server" ImageUrl="~/App_Data/logo.gif" /> 
                                                                    </td> 
                                                                </tr> 
                                                                <tr> 
                                                                    <td colspan="4" align="left" style="border-top-style: solid; border-bottom-style: solid; border-top-width: 1px; border-bottom-width: 1px; border-top-color: #000000; border-bottom-color: #000000; padding-top: 5px; padding-bottom: 5px;">  
                                                                       <b> Title: </b><font color="#0033CC">Projects</font> <br /> 
                                                                        Author: <b> 
                                                                        <font color="#0033CC"><asp:LoginName ID="LoginName1" runat="server"/>  
                                                                        </b></font>  
                                                                        <br /> 
                                                                    </td> 
                                                                    <td align="right" colspan="4"   
                                                                        style="border-top-style: solid; border-bottom-style: solid; border-top-width: 1px; border-bottom-width: 1px; border-top-color: #000000; border-bottom-color: #000000; padding-top: 5px; padding-bottom: 5px;">  
                                                                        Date:  
                                                                        <font color="#0033CC"><asp:Label ID="Label16" runat="server" Text="<%# DateTime.Now %>"></asp:Label></font>  
                                                                    </td> 
                                                                </tr> 
                                                                <tr> 
                                                                    <td align="center" width="30px">  
                                                                        <asp:Label ID="Label1" runat="server" Text="ID" CssClass="boldHeader"></asp:Label> 
                                                                    </td> 
                                                                    <td align="center" width="100px">  
                                                                        <asp:Label ID="Label2" runat="server" CssClass="boldHeader" Text="Name"></asp:Label> 
                                                                    </td> 
                                                                    <td align="center" width="100px">  
                                                                        <asp:Label ID="Label3" runat="server" CssClass="boldHeader" Text="Subject"></asp:Label> 
                                                                    </td> 
                                                                    <td align="center" width="100px" colspan="2">  
                                                                        <asp:Label ID="Label4" runat="server" CssClass="boldHeader"   
                                                                            Text="Project status"></asp:Label> 
                                                                    </td> 
                                                                    <td align="center" width="120px">  
                                                                        <asp:Label ID="Label5" runat="server" CssClass="boldHeader"   
                                                                            Text="Project manager"></asp:Label> 
                                                                    </td> 
                                                                    <td align="center" width="150px">  
                                                                        <asp:Label ID="Label6" runat="server" CssClass="boldHeader" Text="Company"></asp:Label> 
                                                                    </td> 
                                                                    <td align="center" width="150px">  
                                                                        <asp:Label ID="Label7" runat="server" CssClass="boldHeader" Text="SLA template"></asp:Label> 
                                                                    </td> 
                                                                </tr> 
                                                            </table> 
                                                        </HeaderTemplate> 
                                                        <ItemTemplate> 
                                                            <table style="width:100%;">  
                                                                <tr> 
                                                                    <td width="30px">  
                                                                        <asp:Label ID="Label8" runat="server" CssClass="labelHead"   
                                                                            Text='<%# Eval("ID") %>'></asp:Label> 
                                                                    </td> 
                                                                    <td width="100px">  
                                                                        <asp:Label ID="Label9" runat="server" CssClass="labelHead"   
                                                                            Text='<%# Eval("Name") %>'></asp:Label> 
                                                                    </td> 
                                                                    <td width="100">  
                                                                        <asp:Label ID="Label10" runat="server" CssClass="labelHead"   
                                                                            Text='<%# Eval("Subject") %>'></asp:Label> 
                                                                    </td> 
                                                                    <td width="100px">  
                                                                        <asp:Label ID="Label11" runat="server" CssClass="labelHead"   
                                                                            Text='<%# Eval("[Project status]") %>'></asp:Label> 
                                                                    </td> 
                                                                    <td width="120px">  
                                                                        <asp:Label ID="Label12" runat="server" CssClass="labelHead"   
                                                                            Text='<%# Eval("[Project manager]") %>'></asp:Label> 
                                                                    </td> 
                                                                    <td width="150px">  
                                                                        <asp:Label ID="Label13" runat="server" CssClass="labelHead"   
                                                                            Text='<%# Eval("Company") %>'></asp:Label> 
                                                                    </td> 
                                                                    <td width="150px">  
                                                                        <asp:Label ID="Label14" runat="server" CssClass="labelHead"   
                                                                            Text='<%# Eval("[SLA template]") %>'></asp:Label> 
                                                                    </td> 
                                                                </tr> 
                                                            </table> 
                                                        </ItemTemplate> 
                                                    </telerik:GridTemplateColumn> 
                                                </Columns> 
                                                  
                                                <editformsettings> 
                                                    <formtemplate> 
                                                        <telerik:RadUpload ID="RadUpload1" Runat="server">  
                                                        </telerik:RadUpload> 
                                                    </formtemplate> 
                                                </editformsettings> 
                                                <AlternatingItemStyle BackColor="#ECF8FF" /> 
                                                <PagerStyle Mode="NextPrevAndNumeric" PagerTextFormat=" {4} &amp;nbsp;" /> 
                                            </mastertableview> 
                                            <clientsettings   
                                                enablepostbackonrowclick="True">  
                                                <clientevents onrowdblclick="RowDblClick" /> 
                                            </clientsettings> 
                                            <filtermenu enabletheming="True">  
                                                <collapseanimation duration="200" type="OutQuint" /> 
                                            </filtermenu> 
                                            <EditItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="True"   
                                                Font-Strikeout="False" Font-Underline="True" Wrap="True" /> 
                                        </telerik:RadGrid> 
                                        <asp:SqlDataSource ID="SqlDataSource1" runat="server"   
                                            ConnectionString="<%$ ConnectionStrings:WorkFlowBaseConnectionString %>" SelectCommand="SELECT     Projecttbl.id as ID, Projecttbl.name as Name, Projecttbl.subject as Subject,   
            ProjectStatustbl.name AS [Project status], Usertbl.userId as [Project manager],   
                          Companytbl.name AS [Company], SLATemplatetbl.name AS [SLA template]  
    FROM         Projecttbl LEFT OUTER  JOIN  
                          ProjectStatustbl ON Projecttbl.projectstatusid = ProjectStatustbl.id LEFT OUTER  JOIN  
                          Usertbl ON Projecttbl.userid = Usertbl.id LEFT OUTER  JOIN  
                          Companytbl ON Projecttbl.companyid = Companytbl.id LEFT OUTER  JOIN  
                          SLATemplatetbl ON Projecttbl.slatemplateid = SLATemplatetbl.id"></asp:SqlDataSource> 
                                    </td> 
                                </tr> 
                                <tr> 
                                    <td align="center" class="style2">  
                                        &nbsp;</td> 
                                </tr> 
                            </table> 
                        </ContentTemplate> 
                    </asp:UpdatePanel> 
                    </fieldset> 
               </td> 
            </tr> 
        </table> 
    </div> 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnableHistory="True">  
    </telerik:RadAjaxManager> 
    </form> 
</body> 
</html> 
 

c# code is:
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;  
using Telerik.Web.UI;  
 
namespace FireBall.forms.projects  
{  
    public partial class projectrptexport : System.Web.UI.Page  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            if (!Page.IsPostBack)  
            {  
                paperSizeList.DataSource = Enum.GetNames(typeof(GridPaperSize));  
                paperSizeList.DataBind();  
            }  
 
            RadGrid1.ExportSettings.Pdf.PaperSize = (GridPaperSize)Enum.Parse(typeof(GridPaperSize), paperSizeList.SelectedValue);  
 
        }  
 
        protected void RadGrid1_ExcelMLExportRowCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowCreatedArgs e)  
        {  
            if (e.RowType == Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLRowType.DataRow)  
            {  
                if (e.Row.Cells[0] != null && ((string)e.Row.Cells[0].Data.DataItem).Contains("U"))  
                {  
                    e.Row.Cells[0].StyleValue = "MyCustomStyle";  
                }  
            }  
        }  
 
        protected void RadGrid1_ExcelMLExportStylesCreated(object source, Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLStyleCreatedArgs e)  
        {  
            foreach (Telerik.Web.UI.GridExcelBuilder.StyleElement style in e.Styles)  
            {  
                if (style.Id == "headerStyle")  
                {  
                    style.FontStyle.Bold = true;  
                    style.FontStyle.Color = System.Drawing.Color.Gainsboro;  
                    style.InteriorStyle.Color = System.Drawing.Color.Wheat;  
                    style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;  
                }  
                else if (style.Id == "itemStyle")  
                {  
                    style.InteriorStyle.Color = System.Drawing.Color.WhiteSmoke;  
                    style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;  
                }  
                else if (style.Id == "alternatingItemStyle")  
                {  
                    style.InteriorStyle.Color = System.Drawing.Color.LightGray;  
                    style.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;  
                }  
            }  
 
            Telerik.Web.UI.GridExcelBuilder.StyleElement myStyle = new Telerik.Web.UI.GridExcelBuilder.StyleElement("MyCustomStyle");  
            myStyle.FontStyle.Bold = true;  
            myStyle.FontStyle.Italic = true;  
            myStyle.InteriorStyle.Color = System.Drawing.Color.Gray;  
            myStyle.InteriorStyle.Pattern = Telerik.Web.UI.GridExcelBuilder.InteriorPatternType.Solid;  
            e.Styles.Add(myStyle);  
        }  
 
        public void ConfigureExport()  
        {  
            //RadGrid1.ExportSettings.ExportOnlyData = CheckBox1.Checked;  
            //RadGrid1.ExportSettings.IgnorePaging = CheckBox2.Checked;  
            //RadGrid1.ExportSettings.OpenInNewWindow = CheckBox3.Checked;  
        }  
 
        protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)  
        {  
 
        }  
         
            protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)    
            {    
                if (e.CommandName == RadGrid.ExportToPdfCommandName)    
                {    
                    //isPdfExport = true;    
                }    
            }  
 
            protected void Button1_Click(object sender, EventArgs e)  
            {  
                ConfigureExport();  
                RadGrid1.MasterTableView.ExportToExcel();  
            }  
 
            protected void Button2_Click(object sender, EventArgs e)  
            {  
                ConfigureExport();  
                RadGrid1.MasterTableView.ExportToPdf();  
            }    
 
    }  
}  
 

Regards
0
Raul
Top achievements
Rank 1
answered on 29 Jan 2009, 08:17 AM
any one can help??
0
Raul
Top achievements
Rank 1
answered on 29 Jan 2009, 01:32 PM
Is this problem has no solution at telerik team??
0
Raul
Top achievements
Rank 1
answered on 01 Feb 2009, 11:24 AM
Is this problem has no solution at telerik team??
0
Daniel
Telerik team
answered on 02 Feb 2009, 12:24 PM
Hello Raul,

Please remove the IsPostBack check to allow RadGrid to export your data.

Furthermore I recommend you use Advanced data binding with NeedDataSource as described in the following article:
Advanced Data-binding

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Raul
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Raul
Top achievements
Rank 1
Share this question
or