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

RadGrid Export to PDF Problem

1 Answer 162 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sunil
Top achievements
Rank 1
Sunil asked on 30 Jul 2010, 12:49 PM
Hi all,

I have a problem exporting PDFs... basically when I click on my dropdown from RadToolBar, nothing happens. Below is my code in the user control. Its the "Export Current View" button with CommandName="ExportToPDF."

If it means anything, the RadGrid is in a WebUserControl which is loaded into an aspx page.

Thanks for any help,

Sunny

<telerik:RadGrid ID="RadGrid_Logs" runat="server" AutoGenerateColumns="false" 
           AllowMultiRowSelection="false" AllowPaging="True" AllowCustomPaging="True" PageSize="10" AllowAutomaticInserts="false"
           GridLines="None" CellPadding="0" AllowSorting="false" Skin="Default" OnItemDataBound="Log_Translate"
           ItemStyle-VerticalAlign="Top" OnNeedDataSource="RadGrid_Logs_NeedDataSource">
               <ExportSettings IgnorePaging="false" OpenInNewWindow="true">
                   <Pdf PageHeight="297mm" PageWidth="210mm" PageTitle="OnTime System Logs" />
               </ExportSettings>
               <PagerStyle Mode="NextPrevAndNumeric"/>
               <MasterTableView Width="100%" CommandItemDisplay="Top" GridLines="None" AllowAutomaticInserts="false">
               <CommandItemSettings ShowAddNewRecordButton="false" />
               <CommandItemTemplate>
                   <telerik:RadToolBar ID="RadToolBar_Logs" runat="server" Skin="Default" 
                   OnButtonClick="RadToolBar_Logs_CommandClick">
                       <Items>
                           <telerik:RadToolBarDropDown Text="Export">
                           <Buttons>
                               <telerik:RadToolBarButton Text="Export Current View"  Group="Bold" CheckOnClick="true" AllowSelfUnCheck="true" 
                                CommandName="ExportToPDF"/>
                               <telerik:RadToolBarButton Text="Export All Records" Group="Italic" CheckOnClick="true" AllowSelfUnCheck="true" />
                           </Buttons>
                           </telerik:RadToolBarDropDown>
                           <telerik:RadToolBarButton Text="Control Terminal" Visible="true"
                            ImageUrl="Images/Edit.gif" runat="server" ID="Edit">
                           </telerik:RadToolBarButton>
                           <telerik:RadToolBarButton Text="Refresh Terminals" Visible="true"
                            ImageUrl="Images/Refresh.gif" runat="server" ID="Refresh">
                           </telerik:RadToolBarButton>
                       </Items>
                   </telerik:RadToolBar>
               </CommandItemTemplate>
                   <Columns>
                       <telerik:GridTemplateColumn UniqueName="Terminal_Left_Column" HeaderText="Type" HeaderStyle-Width="40%">
                           <ItemTemplate>
                                 
                               <asp:Panel ID="Panel3" runat="server" CssClass="logs_table_text">
                               <asp:Literal ID="Literal_Log_DateTime" runat="server" 
                                   Text='<%# Eval("Log_DateTime").ToString() %>'></asp:Literal>
                               <br />
                               <asp:Literal ID="Label_Log_Category" runat="server" 
                                   Text='<%# Eval("Log_Category").ToString() %>'></asp:Literal>
                               <br />
                                <asp:Literal ID="Literal_Indent" runat="server" Text="-"></asp:Literal>
                               <asp:Literal ID="Label_Log_Type" runat="server" 
                                   Text='<%# Eval("Log_Type").ToString() %>'></asp:Literal>
                           </asp:Panel>
                           </ItemTemplate>
                       </telerik:GridTemplateColumn>
                         
                       <telerik:GridTemplateColumn UniqueName="Terminal_Right_Column" HeaderText="Description" HeaderStyle-Width="60%">
                           <ItemTemplate>
                           <asp:Panel ID="Panel4" runat="server" CssClass="logs_table_text" >
                               <asp:Literal ID="Label_Log_Description" runat="server" 
                                   Text='<%# Eval("Log_Description").ToString() %>'></asp:Literal>
                           </asp:Panel>
                           </ItemTemplate>
                       </telerik:GridTemplateColumn>

1 Answer, 1 is accepted

Sort by
0
Sunil
Top achievements
Rank 1
answered on 01 Aug 2010, 06:03 PM
Hi all,

I've figured this out. The reason is that I am using Ajax. In order for the PDF to work, it needs a full postback, not an asynchronous one like Ajax enabled controls do. You basically have to set whatever control that initiates the PDF creation to do a full postback, not an ajax one.

This page was helpful:
http://www.telerik.com/community/code-library/aspnet-ajax/general/export-radgrid-content-to-excel-word-csv-pdf-with-ajax-enabled.aspx

And the code I used to correct my problem: (Notice how I have to set the scriptmanager to the main page as thats where my script manager is located)

protected void RadGrid_Logs_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                //GridDataItem item = (GridDataItem)e.Item;
                //string s = item.FindControl[]
                //Literal Button btn = (e.Item as GridDataItem)["TemplateColumn"].FindControl("Button1") as Button;
                //ScriptManager tempTestScriptMgr = ScriptManager.GetCurrent(this.Page);
                //tempTestScriptMgr.RegisterPostBackControl(btn);
            }
            if (e.Item is GridCommandItem)
            {
                RadToolBar temptb = (e.Item as GridCommandItem).FindControl("RadToolBar_Logs") as RadToolBar;
                RadToolBarDropDown tempsp = temptb.Items.FindItemByText("Export") as RadToolBarDropDown;
                if (tempsp != null)
                {
                    ScriptManager tempTestScriptMgr = ScriptManager.GetCurrent(this.Page);
                    tempTestScriptMgr.RegisterPostBackControl(temptb);
                }
  
            }
        }

I hope this helps somebody!

Sunny

Tags
Grid
Asked by
Sunil
Top achievements
Rank 1
Answers by
Sunil
Top achievements
Rank 1
Share this question
or