Export to Excel or PDF in RadGrid


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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: