Follow these steps to export all data from data source into Microsoft Office Excel™ 2003 file format.
-
Create a web page (ASP.NET Web Form) with WebDataGrid bound to SqlDataSource control. Enable Paging behavior for that grid.
<ig:WebDataGrid runat="server" ID="wdgCustomers"
DataSourceID="SqlDsCustomers"
DataKeyFields="CustomerID"
AutoGenerateColumns="
>
<Columns>
<ig:BoundDataField Key="Country" DataFieldName="Country" Header-Text="Country" />
<ig:BoundDataField Key="City" DataFieldName="City" Header-Text="City" />
<ig:BoundDataField Key="CompanyName" DataFieldName="CompanyName" Header-Text="Company" />
<ig:BoundDataField Key="ContactName" DataFieldName="ContactName"Header-Text="Contact" />
<ig:BoundDataField Key="Phone" DataFieldName="Phone" Header-Text="Phone" />
</Columns>
<Behaviors>
<ig:Paging PageSize="5" QuickPages="3" Enabled="true" PagerMode="NumericFirstLast" />
</Behaviors>
</ig:WebDataGrid>
-
Drag a WebExcelExporter control from the Visual Studio Toolbox onto your page:
-
Set the WebExcelExporter’s property ExportMode to Download
-
Set the control’s ID property to WebExcelExporter
-
Set the control’s DownloadName property to ExportedData
-
Set the control’s DataExportMode property to AllDataInDataSource
<ig:WebExcelExporter runat="server" ID="WebExcelExporter" ExportMode ="Download" DownloadName="ExportedData" DataExportMode="AllDataInDataSource"
/>
-
Drag a Button control from Visual Studio Toolbox onto your page:
-
Set the button’s ID property to btnExport
-
Set the control’s Text property to Export Data
-
Set the control’s OnClick to btnExport_Click
-
Define the btnExport_Click handler in the code-behind and call one of the WebExcelExporter’s Export() method overloads
In Code Behind (C#): |
protected void btnExport_Click(object sender, EventArgs e)
this.WebExcelExporter.Export(this.wdgCustomers);
|
<asp:Button runat="server" ID="btnExport" Text="Export Data" OnClick="btnExport_Click" />
-
Run the application.
-
Click the “Export Data” button.
After clicking the “Export Data” button, your browser will ask you whether you want to open or save file named “ExportedData.xls”:
When you open the file, you will see the whole data exported, rather than the currently visible data in the grid (current page).