ASPxGridViewExporter NullReferenceException

时间:2018-12-04 15:37:42

标签: devexpress

我在导出到XLS的ASPx Web窗体上有一个网格。 我想从标记中删除ASPxGridViewExporter并仅使用后面的代码。

*删除:

[ASPx]
        <dx:ASPxGridViewExporter ID="gvExporter"  GridViewID="grdList" runat="server">
        </dx:ASPxGridViewExporter>

在后面的代码中。

当控件位于aspx页面上时,此方法有效

[VB.NET]
    Sub ExportToExcel(sGrid As String, sTitle As String)

        Dim ExportSettings As New DevExpress.XtraPrinting.XlsExportOptionsEx() With {.SheetName = "Form"}
        gvExporter.GridViewID = sGrid
        gvExporter.WriteXlsToResponse(sTitle, ExportSettings)

    End Sub

我想使用这样的代码,但是现在这段代码抛出System.NullReferenceException,但没有告诉我什么是空

[VB.NET]
    Sub ExportToExcel(sGrid As String, sTitle As String)

        Dim ExportSettings As New DevExpress.XtraPrinting.XlsExportOptionsEx() With {.SheetName = "Form"}
        Dim gvExporter As New ASPxGridViewExporter

        BindList()

        gvExporter.ID = "exporter1"
        gvExporter.GridViewID = "grdList"
        gvExporter.DataBind()
        gvExporter.WriteXlsToResponse(sTitle, ExportSettings)  <<< Error thrown here "System.NullReferenceException"

    End Sub

我想使方法背后的代码起作用。

0 个答案:

没有答案