tags:

views:

44

answers:

1

please help guys.. i'm newbie in asp.net c#, i'm using devexpress aspxgridview for my proposed project,it's seem strange to export detail aspgridview with master aspxgridview aboveit, any idea how to make custom export detail aspxgridview to xls. very thank for advance and help..

A: 

You can use the built in devexpress exporters.

You can add the exporter control in the code in front and tie it to the grid you want to export, <dxwgv:ASPxGridViewExporter ID="aspxGridExporter" runat="server" GridViewID="aspxGrid" />

Then add a button to trigger the export event, <dxe:ASPxButton ID="btnXlsExport" runat="server" Text="Export to Excel" UseSubmitBehavior="False" OnClick="DxeXlsExport_Click" TabIndex="130" />

Then on the code behind, handle the export button click event to export the grid

 public void DxeXlsExport_Click(object sender, EventArgs e)
{
    //these export options are not required but they can make the result xls customizable
    DevExpress.XtraPrinting.XlsExportOptions exportOptions = new DevExpress.XtraPrinting.XlsExportOptions();
    exportOptions.ExportHyperlinks = false;
    exportOptions.UseNativeFormat = false;

    //make sure to rebind the data here if it was not bound on page load
    //here you can also hide any columns you dont want to export
    //ie. aspxGrid.Columns["dontExportColumn"].Visible = false;

    Response.ClearContent();
    Response.ClearHeaders();
    Response.Buffer = true;
    Response.AppendHeader("cache-control", "no-transform");
    downloadAspxGridExporter.WriteXlsToResponse("GridExport", true, exportOptions);
    HttpContext.Current.ApplicationInstance.CompleteRequest();
    Response.End();

}
Andre Santos