Hi, I'm having problems to export the data of my grid.
My code to export the data:
Protected Sub btExpCsv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btExpCsv.Click
RadGrid1.ExportSettings.ExportOnlyData = True
RadGrid1.ExportSettings.IgnorePaging = True
RadGrid1.ExportSettings.OpenInNewWindow = True
RadGrid1.MasterTableView.ExportToCSV()
End Sub
Protected Sub btExpExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btExpExcel.Click
RadGrid1.ExportSettings.ExportOnlyData = True
RadGrid1.ExportSettings.IgnorePaging = True
RadGrid1.ExportSettings.OpenInNewWindow = True
RadGrid1.MasterTableView.ExportToExcel()
End Sub
Protected Sub btExpPdf_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btExpPdf.Click
Dim dataAtual As Date
dataAtual = System.DateTime.Now
RadGrid1.ExportSettings.ExportOnlyData = False
RadGrid1.ExportSettings.IgnorePaging = True
RadGrid1.ExportSettings.OpenInNewWindow = True
RadGrid1.ExportSettings.Pdf.AllowCopy = True
RadGrid1.ExportSettings.Pdf.PaperSize = GridPaperSize.Oficio
RadGrid1.ExportSettings.Pdf.PageTitle = "Relatório Pontos Analógicos - " & dataAtual
RadGrid1.MasterTableView.ExportToPdf()
End Sub
The grid:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" DataSourceID="sqlEventos"
GridLines="None" AutoGenerateColumns="False" AllowSorting="True"
Skin="Vista">
<HeaderContextMenu EnableTheming="True">
<CollapseAnimation Duration="200" Type="OutQuint" />
</HeaderContextMenu>
<MasterTableView DataSourceID="sqlEventos" PagerStyle-Mode="NextPrevAndNumeric" PageSize="25">
<RowIndicatorColumn Visible="True">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="e3timestamp" HeaderText="Data/Hora"
SortExpression="timestamp" UniqueName="column">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="cd_ponto_digital" HeaderText="Ponto"
UniqueName="column1">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="txt_alarme" HeaderText="Mensagem"
UniqueName="column2">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="fieldvalue" HeaderText="Valor"
UniqueName="column3">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="quality" HeaderText="Qualidade"
UniqueName="column4">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="timestamp" UniqueName="column4"
Visible="false">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings AllowExpandCollapse="False" AllowGroupExpandCollapse="False"
ColumnsReorderMethod="Reorder">
<Selecting EnableDragToSelectRows="False" />
<Resizing AllowColumnResize="True" AllowRowResize="True"
EnableRealTimeResize="True" />
</ClientSettings>
<FilterMenu EnableTheming="True">
<CollapseAnimation Duration="200" Type="OutQuint" />
</FilterMenu>
</telerik:RadGrid>
I have no idea of what is causing the error below:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Stack Trace:
Any help would be very appreciated.
Simón de Lizarza
My code to export the data:
Protected Sub btExpCsv_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btExpCsv.Click
RadGrid1.ExportSettings.ExportOnlyData = True
RadGrid1.ExportSettings.IgnorePaging = True
RadGrid1.ExportSettings.OpenInNewWindow = True
RadGrid1.MasterTableView.ExportToCSV()
End Sub
Protected Sub btExpExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btExpExcel.Click
RadGrid1.ExportSettings.ExportOnlyData = True
RadGrid1.ExportSettings.IgnorePaging = True
RadGrid1.ExportSettings.OpenInNewWindow = True
RadGrid1.MasterTableView.ExportToExcel()
End Sub
Protected Sub btExpPdf_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btExpPdf.Click
Dim dataAtual As Date
dataAtual = System.DateTime.Now
RadGrid1.ExportSettings.ExportOnlyData = False
RadGrid1.ExportSettings.IgnorePaging = True
RadGrid1.ExportSettings.OpenInNewWindow = True
RadGrid1.ExportSettings.Pdf.AllowCopy = True
RadGrid1.ExportSettings.Pdf.PaperSize = GridPaperSize.Oficio
RadGrid1.ExportSettings.Pdf.PageTitle = "Relatório Pontos Analógicos - " & dataAtual
RadGrid1.MasterTableView.ExportToPdf()
End Sub
The grid:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" DataSourceID="sqlEventos"
GridLines="None" AutoGenerateColumns="False" AllowSorting="True"
Skin="Vista">
<HeaderContextMenu EnableTheming="True">
<CollapseAnimation Duration="200" Type="OutQuint" />
</HeaderContextMenu>
<MasterTableView DataSourceID="sqlEventos" PagerStyle-Mode="NextPrevAndNumeric" PageSize="25">
<RowIndicatorColumn Visible="True">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="e3timestamp" HeaderText="Data/Hora"
SortExpression="timestamp" UniqueName="column">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="cd_ponto_digital" HeaderText="Ponto"
UniqueName="column1">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="txt_alarme" HeaderText="Mensagem"
UniqueName="column2">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="fieldvalue" HeaderText="Valor"
UniqueName="column3">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="quality" HeaderText="Qualidade"
UniqueName="column4">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="timestamp" UniqueName="column4"
Visible="false">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings AllowExpandCollapse="False" AllowGroupExpandCollapse="False"
ColumnsReorderMethod="Reorder">
<Selecting EnableDragToSelectRows="False" />
<Resizing AllowColumnResize="True" AllowRowResize="True"
EnableRealTimeResize="True" />
</ClientSettings>
<FilterMenu EnableTheming="True">
<CollapseAnimation Duration="200" Type="OutQuint" />
</FilterMenu>
</telerik:RadGrid>
I have no idea of what is causing the error below:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
|
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.] Telerik.Web.UI.GridTableView.PrepareExport() +14 Telerik.Web.UI.Grid.Export.TableViewExporter.PrepareForExport() +171 Telerik.Web.UI.Grid.Export.TableViewExporter.page_PreRender(Object sender, EventArgs e) +5 System.EventHandler.Invoke(Object sender, EventArgs e) +0 System.Web.UI.Control.OnPreRender(EventArgs e) +8679510 System.Web.UI.Control.PreRenderRecursiveInternal() +80 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842 |
Any help would be very appreciated.
Simón de Lizarza