如何在mastergrid中为aspxgridview详细信息自定义导出到xls

时间:2010-09-03 14:11:26

标签: aspxgridview

请帮助大家..我是asp.net c#的新手,我正在使用devexpress aspxgridview来建议我的项目,导出详细信息aspgridview与主aspxgridview上面似乎很奇怪,任何想法如何制作自定义导出细节aspxgridview到xls。 非常感谢前进和帮助..

1 个答案:

答案 0 :(得分:1)

您可以使用内置的devexpress导出器。

您可以在前面的代码中添加导出器控件并将其绑定到要导出的网格,  <dxwgv:ASPxGridViewExporter ID="aspxGridExporter" runat="server" GridViewID="aspxGrid" />

然后添加一个按钮来触发导出事件,  <dxe:ASPxButton ID="btnXlsExport" runat="server" Text="Export to Excel" UseSubmitBehavior="False" OnClick="DxeXlsExport_Click" TabIndex="130" />

然后在后面的代码中,处理导出按钮单击事件以导出网格

 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();

}