Hello,
I have a little problem hope that you can help me with this:
I have Rad Grid and I'm trying to export the Grid to PDF by clicking on the button:
Here is my Code:
<telerik:RadGrid
ID="rgActivities"
runat="server"
AutoGenerateColumns="False"
AllowPaging="True"
AllowSorting="True"
PageSize="16"
CellSpacing="0" GridLines="None"
OnItemCommand="rgActivities_ItemCommand"
OnSortCommand="rgActivities_OnSortCommand"
OnPageIndexChanged="rgActivities_OnPageIndexChanged"
EnableHeaderContextFilterMenu="True"
Width="933px"
Height="528px">
******* I have 6 Columns in the Grid *****
<asp:Button ID="mngBtnPDF" runat="server" ToolTip="Export To PDF" Text="" Visible ="false" OnClick="btnpdf_Click" CommandName="btnPDF_Click" />
******Code Behind*****
Protected Sub btnPDF_Click(ByVal sender As Object, ByVal e As System.EventArgs)
isExport = True
rgActivities.ExportSettings.ExportOnlyData = True
rgActivities.ExportSettings.IgnorePaging = True
rgActivities.ExportSettings.OpenInNewWindow = True
rgActivities.ExportSettings.ExportOnlyData = True
rgActivities.ExportSettings.Pdf.PageWidth = Unit.Parse("297mm")
rgActivities.ExportSettings.Pdf.PageHeight = Unit.Parse("210mm")
rgActivities.MasterTableView.ExportToPdf()
End Sub
Nothing happens Please help me.
10 Answers, 1 is accepted

From the given code it works fine, may i ask what is isExport=true? In case if your RadGrid is ajaxified then, the asynchronous postback should be canceled when performing an export. You can find more information about it here. Please add the following code snippet to your code if your Grid is Ajaxified and see if it helps, else please provide your full code snippet.
ASPX:
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
ClientEvents
OnRequestStart
=
"onRequestStart"
></
ClientEvents
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"rgActivities"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"rgActivities"
></
telerik:AjaxUpdatedControl
>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
JS:
<script type=
"text/javascript"
>
function
onRequestStart(sender, args)
{
if
(args.get_eventTarget().indexOf(
"mngBtnPDF"
) >= 0)
{
args.set_enableAjax(
false
);
}
}
</script>
Thanks,
Princy

Thank you for the answer now the PDF is popsup but I the issue it won't show anything.
can you please help me with that?
this is my code behind:
Protected Sub btnPDF_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'isExport = True
rgActivities.ExportSettings.ExportOnlyData = True
rgActivities.ExportSettings.IgnorePaging = True
rgActivities.ExportSettings.OpenInNewWindow = True
rgActivities.ExportSettings.ExportOnlyData = True
rgActivities.ExportSettings.Pdf.PageWidth = Unit.Parse("297mm")
rgActivities.ExportSettings.Pdf.PageHeight = Unit.Parse("210mm")
' ''Specific Column Width
Dim column As GridColumn = rgActivities.MasterTableView.GetColumn("ActivityStatus")
column.HeaderStyle.Width = Unit.Pixel(40)
''First try hide row
' rgActivities.MasterTableView.Items(0).Visible = False
''Second Try to hide row
'rgActivities.MasterTableView.EnableHeaderContextFilterMenu = False
''Third try to hide row
' Dim Hideitem As GridFilteringItem = TryCast(rgActivities.MasterTableView.GetItems(GridItemType.FilteringItem)(0), GridFilteringItem)
'Hideitem.Visible = False
'rgActivities.MasterTableView.Columns(8).Visible = False ''Edit Column
rgActivities.MasterTableView.ExportToPdf()
End Sub


Do you have Scrolling/StaticHeaders enabled? If so, please disable this functionality before exporting to PDF.
VB:
Protected
Sub
btnpdf_Click(sender
As
Object
, e
As
EventArgs)
rgActivities.ClientSettings.Scrolling.AllowScroll =
False
rgActivities.ClientSettings.Scrolling.UseStaticHeaders =
False
'Rest of your code
End
Sub
Hope this helps.
Thanks,
Princy

Hello,
I tried it but PDF is open's up without any data. This is my asp.net code:

I tried your code and it works fine at my end. Below is a sample code that i tried. Please check to see if this code works for you.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AutoGenerateColumns
=
"False"
AllowPaging
=
"True"
DataSourceID
=
"SqlDataSource1"
OnItemCommand
=
"RadGrid1_ItemCommand"
Width
=
"400px"
>
<
ExportSettings
IgnorePaging
=
"true"
ExportOnlyData
=
"true"
OpenInNewWindow
=
"true"
>
</
ExportSettings
>
<
ClientSettings
>
<
Selecting
AllowRowSelect
=
"True"
></
Selecting
>
<
Scrolling
AllowScroll
=
"true"
UseStaticHeaders
=
"True"
SaveScrollPosition
=
"true"
FrozenColumnsCount
=
"2"
/>
</
ClientSettings
>
<
MasterTableView
CommandItemDisplay
=
"Top"
TableLayout
=
"Auto"
>
<
Columns
>
<
telerik:GridBoundColumn
HeaderText
=
"OrderID"
DataField
=
"OrderID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
HeaderText
=
"ShipCity"
DataField
=
"ShipCity"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
HeaderText
=
"ShipCountry"
DataField
=
"ShipCountry"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
HeaderText
=
"ShipVia"
DataField
=
"ShipVia"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
HeaderText
=
"ShipRegion"
DataField
=
"ShipRegion"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
HeaderText
=
"CustomerID"
DataField
=
"CustomerID"
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
CommandItemTemplate
>
<
div
style
=
"padding: 5px 5px;"
>
<
table
class
=
"rcCommandTable"
width
=
"100%"
>
<
td
style
=
"float: right"
>
<
asp:Button
ID
=
"BtnPDF"
runat
=
"server"
Text
=
" "
CssClass
=
"rgExpPDF"
CommandName
=
"ExportToPDF"
/>
</
td
>
</
table
>
</
div
>
</
CommandItemTemplate
>
</
MasterTableView
>
</
telerik:RadGrid
>
VB:
Protected
Sub
RadGrid1_ItemCommand(sender
As
Object
, e
As
GridCommandEventArgs)
If
e.CommandName =
"ExportToPDF"
Then
RadGrid1.ClientSettings.Scrolling.AllowScroll =
False
RadGrid1.ClientSettings.Scrolling.UseStaticHeaders =
False
RadGrid1.Rebind()
RadGrid1.MasterTableView.ExportToPdf()
End
If
End
Sub
Thanks,
Princy

Hi
Thank you so much for the help but the PDF coming up without any data
What should I do??
Avihai.
I prepared a small sample based on your code and attached it to this thread. As you could see the exporting to pdf is working properly. Could you please let me know how my sample differs from your real setup?
Regards,
Kostadin
Telerik

Hello,
The pdf export works great but I have other issue on the left side of the grid I have couple of buttons and I tried that they would be load fast using
**************That code I put it after the RadGrid**************
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="LoadingPanel1" onajax >
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="actCategory">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="actSubCategory" LoadingPanelID="LoadingPanel1"/>
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="actLocation">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="actZone" LoadingPanelID="LoadingPanel1"/>
<telerik:AjaxUpdatedControl ControlID="actPersonAssigned" LoadingPanelID="LoadingPanel1"/>
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="GeneralSearchBtn">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="rgActivities" LoadingPanelID="LoadingPanel1"/>
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="DateSearchBtn">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="rgActivities" LoadingPanelID="LoadingPanel1"/>
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="LoadingPanel1" runat="server" BackgroundPosition="Center"></telerik:RadAjaxLoadingPanel>
*********** Back code************
Protected Sub RadAjaxManager1_AjaxSettingCreating(ByVal sender As Object, ByVal e As Telerik.Web.UI.AjaxSettingCreatingEventArgs) Handles RadAjaxManager1.AjaxSettingCreating
If (e.Initiator.ID.StartsWith("mngBtnPDF")) Then
e.UpdatePanel.RenderMode = UpdatePanelRenderMode.Inline
End If
End Sub
now the problem when I click on the PDFbtn the all Grid is Opened throughout the all page
any idea why???
The exporting feature works only with regular postbacks. This means, that the asynchronous postback should be canceled when performing an export.
More information on this topic is available below:
Exclude controls from ajaxifying
Export RadGrid content to Excel/Word/CSV/PDF with Ajax enabled
Regards,
Kostadin
Telerik