Version

Getting Started with WebDocumentExporter

What You Will Accomplish

You will learn how to set up and use WebDocumentExporter to export WebDataGrid / WebHierarchicalDataGrid data into a PDF or XPS document file format.

Follow these steps:

  1. Bind the WebDataGrid retrieving data from Customers table of Northwind.

  2. Drag a WebDocumentExporter control from the Visual Studio Toolbox onto your page:

    1. Set the WebDocumentExporter’s ExportMode property to Download.

    2. Set the control’s ID property to WebDocumentExporter.

    3. Set the control’s DownloadName property to “ExportedData”.

In HTML:

<ig:WebDocumentExporter  runat="server" ID="WebDocumentExporter"
ExportMode ="Download" DownloadName="ExportedData" />
Note
Note:

by default, WebDocumentExporter exports the data in PDF document format. If you want to export in XPS document, you need to set the Format property to XPS.

  1. Drag a Button control from Visual Studio Toolbox onto your page:

    1. Set the button’s ID property to btnExport.

    2. Set the control’s Text property to “Export Data”.

    3. Set the control’s OnClick to “btnExport_Click”.

    4. Define the “btnExport_Click” handler in the code-behind and call WebDocumentExporter’s Export method.

In HTML:

<asp:Button runat="server" ID="btnExport" Text="Export Data" OnClick="btnExport_Click" />
In Code Behind (C#):

protected void btnExport_Click(object sender, EventArgs e)

{

this.WebDocumentExporter.Export(this.whdgCustomers);

}

  1. Run the application.

  2. Click the “Export Data” button.

After clicking the “Export Data” button, your browser will ask you whether you want to open or save the file named “ExportedData.pdf”.

WebDocumentExporter Getting Started with WebDocumentExporter 01.png
Note
Note:

The ExportedData.pdf file will only contain the grid’s visible data. If you want to export all the data in the data source, please refer to Exporting All Data in Data Source.