ComponentOne GridView for ASP.NET WebForms
Working with GridView for ASP.NET Web Forms / Export Service
In This Topic
    Export Service
    In This Topic

    Use the C1 ASP.NET Export Service, to export GridView to Excel, CSV and PDF, without creating a complex export application. This service resides on the application server.

    The advantages of using C1 ASP.NET Export Service are:

    Export Service is a web-application that is deployed on Internet Information Services (IIS). Run the C1ASPNETExportService installer, placed in C:\Program Files\ComponentOne\ASP.NET Web Forms Edition folder. It installs the following files in IIS.

    You can also locate these files at the following location:

    C:\ProgramData\ComponentOne\C1ASPNET\C1APNETExportService

    System Requirements

    Following are the system requirements of the service host:

    You may update .Net framework 4.0 in Microsoft Windows 7 or Microsoft Windows Server 2008 R2. See http://support.microsoft.com/kb/2468871, for more information.

    GridView Export Setting

    Following are the settings, to download the grid in various formats:

    Export to Excel

    Export to CSV:

    Export to PDF

    Usage

    The exportGrid method will be called to export the GridView content to Excel, CSVS or PDF. These steps assume that you have added a button  to the form, on whose click event you would call the export function. Add the following code within the <head></head>tags, to export the GridView to Excel.

                <script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script> 
     <asp:PlaceHolder runat="server">
                <script type="text/javascript">
    
                    $(function () {
                        $("#Button1").click(exportExcel);
                    });
       
                    // Export function
                    function exportExcel() {
                        var fileName = "ExportedGrid";
                        var type = "Xls";
                        var excelSetting = {
                            showGridLines: true,
                            autoRowHeight: true,
                            author: "ComponentOne"
                        };
                        var url = "http://demos.componentone.com/ASPNET/ExportService" + "/exportapi/grid";
                        $("#<%=C1GridView1.ClientID%>").c1gridview("exportGrid", fileName, type, excelSetting, url);
        }
                </script>
        </asp:PlaceHolder>
    

    Add the following code within the <head></head> tags, to export the GridView to a CSV file:

            <script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script>   
     <asp:PlaceHolder ID="PlaceHolder1" runat="server">
                <script type="text/javascript">
    
                    $(function () {
                        $("#Button1").click(exportCsv);
                    });
                   
                    // Export function
                    function exportCsv() {
                        var fileName = "ExportedGrid";
                        var url = "http://demos.componentone.com/ASPNET/ExportService" + "/exportapi/grid";
                        $("#<%=C1GridView1.ClientID%>").c1gridview("exportGrid", fileName, "csv", url);
        }
                </script>
            </asp:PlaceHolder> 
    

    Add the following code within the <head></head> tags, to export the GridView to a PDF:

    <script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script>
        <asp:PlaceHolder ID="PlaceHolder1" runat="server">
                <script type="text/javascript">
    
                    $(function () {
                        $("#Button1").click(exportPdf);
                       
                    });
    
                    // pdf settings
                    function getPdfSetting() {
                            return {
                                repeatHeader: true,
                                landscape: true,
                                autoFitWidth: true,
                                pageSize: {
                                    width: 300,
                                    height: 400
                                },
                                paperKind: 'A4',
                                margins: {
                                    top: 50,
                                    right: 50,
                                    bottom: 50,
                                    left: 50
                                },
                                imageQuality:'Low',
                                compression: 'BestCompression',
                                fontType: 'TrueType',
                                author: 'ComponentOne',
                                creator: 'ComponentOne',
                                subject: 'Grid Export',
                                title: 'Grid Export',
                                producer: 'ComponentOne',
                                keywords: 'Grid, GridView, Export, PDF',                       
                                encryption: 'NotPermit',
                                ownerPassword: '0000',
                                userPassword: '00000',
                                allowCopyContent: true,
                                allowEditAnnotations: true,
                                allowEditContent: true,
                                allowPrint: true,
                            }                                      
                    }    
    
                    // Export function               
                        function exportPdf() {
                        var fileName = 'ExportGrid';
                        var pdfSetting = getPdfSetting();
                        var url = "http://demos.componentone.com/ASPNET/ExportService" + "/exportapi/grid";
                        $("#<%=C1GridView1.ClientID%>").c1gridview("exportGrid", fileName, "pdf", pdfSetting, url);
                        }
    
                </script>
    </asp:PlaceHolder>
    

    The following image displays the properties of the PDF generated:


    In case the file is not downloaded on Internet Explorer, turn off Internet Explorer protected mode to export file or run Internet Explorer as administrator. To turn off the protected mode:

    See Also

    Narrative