Export to Excel or PDF in RadGrid
January 28, 2011 Leave a Comment
Introduction:
RadGrid has a built-in facility to export the grid’s data into different formats like Excel, CSV, Word or PDF and we can export the same as per the system requierement. Here I will show you how to export grid’s data in PDF or Excel format.
Code:
First of all in RadGrid, place the ExportSettings tag as below in the code. Here I have set properties like IgnorePaging equal to True to export all grids data and OpenInNewWindow equal to true to open the export data in a seperate window. Also in ExportSettings section I have defined the width of the PDF page.
<ExportSettingsIgnorePaging=”true”OpenInNewWindow=”true”>
<PdfPageWidth=”1500px”/>
</ExportSettings>
Now in RadAjaxManager of your page add the following event:
ClientEvents-OnRequestStart=”requestStart”
Then, add the following javascript function in your aspx page:
function requestStart(sender, args) {
if (args.get_eventTarget().indexOf(“btnExportToPDF”) > 0 ||
args.get_eventTarget().indexOf(“btnExportToExcel”) > 0)
args.set_enableAjax(false);
}
And then add the command name for the button as like following for PDF or Excel.
CommandName=”ExportToPdf”
and it’s done.