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

[Solved] Problem for "export to PDF"

6 Answers 198 Views
Grid
This is a migrated thread and some comments may be shown as answers.
li bin
Top achievements
Rank 1
li bin asked on 28 Jul 2009, 03:16 AM
Hello all,
I have done a demo of " export to PDF" ,like the Grid / Export to PDF.
I downloaded the PDF,when i open it ,it can't open or sometimes it opened but had nothing. I don't know why.
my code like follows:
<body> 
    <form id="form1" runat="server">  
   
    <div  style="height: 110px; width: 92%">  
            <asp:CheckBox ID="CheckBox1" Text="Export only data" runat="server"></asp:CheckBox> 
            <br /> 
            <asp:CheckBox ID="CheckBox2" Text="Ignore paging (exports all pages)" runat="server"></asp:CheckBox> 
            <br /> 
            <asp:CheckBox ID="CheckBox3" Text="Open exported data in new browser window" runat="server"></asp:CheckBox> 
            <br /> 
            <br /> 
<asp:Button ID="Button1"  Width="150px" Text="Export to Excel" OnClick="Button1_Click" 
runat="server"></asp:Button> 
 
<asp:Button ID="Button2" Width="150px" Text="Export to Word" OnClick="Button2_Click" 
runat="server"></asp:Button> 
<asp:Button ID="Button3"  Width="150px" Text="Export to CSV" OnClick="Button3_Click" 
runat="server"></asp:Button>   
 
        </div> 
    <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"/>          
       <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"   
        DefaultLoadingPanelID="RadAjaxLoadingPanel1" 
            ClientEvents-OnRequestStart="requestStart">  
                <AjaxSettings> 
                    <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting>   
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">  
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                        </UpdatedControls> 
                    </telerik:AjaxSetting>                    
     
               <telerik:AjaxSetting AjaxControlID="RadWindowManager1">  
                </telerik:AjaxSetting> 
                </AjaxSettings> 
            </telerik:RadAjaxManager> 
     
      
        <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None"   
            AllowSorting="True" Skin="Black" Width="745px" AllowPaging="True"   
             OnNeedDataSource="RadGrid1_NeedDataSource"    
     
            AutoGenerateColumns="False">  
             
            <MasterTableView CommandItemDisplay="Top"  DataKeyNames="PermissionsId" 
                PageSize="5">  
                <PagerStyle Mode="NumericPages" /> 
                <CommandItemTemplate> 
                </CommandItemTemplate> 
                <Columns> 
                    <telerik:GridBoundColumn DataField="PermissionsId" DataType="System.Int32" ReadOnly="True" 
                        SortExpression="PermissionsId" UniqueName="PermissionsId" HeaderText="PermissionsId">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="PermissionsName" HeaderText="PermissionsName" SortExpression="PermissionsName" 
                        UniqueName="PermissionsName">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="PermissionsNo" HeaderText="PermissionsNo" SortExpression="PermissionsNo" 
                        UniqueName="PermissionsNo">  
                    </telerik:GridBoundColumn> 
                      
                </Columns> 
                <HeaderStyle Font-Names="Arial Unicode MS"  Font-Size="16px" HorizontalAlign="Center" /> 
            </MasterTableView> 
        </telerik:RadGrid> 
          
    </form> 
</body> 

here is my .cs code:
  public partial class WebForm3pdf : System.Web.UI.Page  
    {  
        PermissionsService pre = new PermissionsService();  
        protected void Page_Load(object sender, EventArgs e)  
        {  
 
        }  
 
        protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)  
        {  
            this.RadGrid1.DataSource = pre.GetAll();  
 
        }  
 
        protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)  
        {  
            if (e.Item is GridDataItem || e.Item is GridHeaderItem)  
            {  
                e.Item.Style["color"] = "white"; //Default color for headeritem/dataitem  
                foreach (TableCell cell in e.Item.Cells)  
                {  
                    cell.Style["font-family"] = "Verdana";  
                    cell.Style["text-align"] = "center";  
                    cell.Style["vertical-align"] = "middle";  
                    cell.Style["font-size"] = "16px";  
                }  
                GridDataItem item = e.Item as GridDataItem;  
                if (item != null)  
                {  
                    item["PermissionsName"].Style["font-weight"] = "bolder";  
                    item["PermissionsNo"].Style["font-family"] = "Arial Unicode MS";  
                    item["PermissionsNo"].Style["color"] = "#bbbbbb";  
 
                }  
            }  
            switch (e.Item.ItemType) //Mimic RadGrid appearance for the exported PDF file  
            {  
                case GridItemType.Item: e.Item.Style["background-color"] = "#4F4F4F"; break;  
                case GridItemType.AlternatingItem: e.Item.Style["background-color"] = "#494949"; break;  
                case GridItemType.Header: e.Item.Style["background-color"] = "#2B2B2B"; break;  
                case GridItemType.CommandItem: e.Item.Style["background-color"] = "#000000"; break;  
            }  
            if (e.Item is GridCommandItem)  
            {  
                e.Item.PrepareItemStyle(); //needed to span the image over the CommandItem cells  
            }  
        }  
    } 

Thank you!

6 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 28 Jul 2009, 07:21 AM
Hello li bin,

The code-snippets you posted below looks correct. Please download the sample project (based on your code) that is attached to this post.

Let me know whether it is working as expected on your end.

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
li bin
Top achievements
Rank 1
answered on 28 Jul 2009, 08:07 AM

Hello telerik team,
Thank you for you reply.

I have done your libin.zip(cope the file of .aspx and .cs), it is all the same like my demo, sometimes it can't open and sometimes it opens but has nothing. 
Where is the wrong??

Thank you!

0
Daniel
Telerik team
answered on 28 Jul 2009, 04:10 PM
Hello Li,

Please isolate the issue in a simple working project and attach it to regular support ticket. This way we will be able to reproduce/debug the problem locally.

Thank you for your understanding.

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
li bin
Top achievements
Rank 1
answered on 29 Jul 2009, 02:21 AM

Hello telerik,
Did you sucess for this libin.zip in your own computer? I have tested it in my computer , it can open and have nothing.

I don't know why.

0
Sebastian
Telerik team
answered on 29 Jul 2009, 06:43 AM
Hi li bin,

I extracted the zip locally and the files in it were available (aspx page along with its code-behind and sample web.config). Try again and let us know how it goes.

All the best,
Daniel,
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
li bin
Top achievements
Rank 1
answered on 29 Jul 2009, 07:32 AM
I have isolated the zip in a simple working project and attached it to regular support ticket.
but when I click the button , it sometimes turned "文件"Default.aspx"被保护。请输入"文档打开口令"." or sometimes "文件已损坏且无法修复".
your zip haven't been changed anyplace.
I don't know why.
THANKS!
Tags
Grid
Asked by
li bin
Top achievements
Rank 1
Answers by
Daniel
Telerik team
li bin
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or