Hi, I am trying to get a PDF grid export working in VB.Net using the following code
Protected Sub FlatGrid_ServerPdfExporting(ByVal sender As Object, ByVal e As Syncfusion.JavaScript.Web.GridEventArgs)
Dim exp As PdfExport = New PdfExport
exp.Export(Grid6.Model, CType(Grid6.DataSource, IEnumerable), "JExport.pdf")
End Sub
I get the following error when clicking the export button...
Unable to cast object of type 'System.Data.DataTable' to type 'System.Collections.IEnumerable'.
If I comment out the exp.Export line and try again I get the following error ...
Illegal characters in path.
Could you please advise how to resolve this in VB.Net
Also, Is it possible to add some descriptive text next to the PDF Export button ??
Many thanks , John
Hi John,
Query: I get the following error when clicking the export button... Unable to cast object of type 'System.Data.DataTable' to type 'System.Collections.IEnumerable'.
To avoid this issue, we suggest you follow the below code example,
Your code:
Dim exp As PdfExport = New PdfExport() exp.Export(OrdersGrid.Model, CType(OrdersGrid.DataSource, IEnumerable), "Export.xlsx", ExcelVersion.Excel2010, True, True, "flat-lime")
Modified code:
Dim exp As PdfExport = New PdfExport() exp.Export(OrdersGrid.Model, OrdersGrid.DataSource, "Export.pdf", True, True, "flat-lime")
|
Please refer to the below sample,
https://www.syncfusion.com/downloads/support/directtrac/general/ze/vbexport1674555985
If you still facing issue, please provide the following information
The requested information will be helpful to proceed further.
Query: Is it possible to add some descriptive text next to the PDF Export button ??
We achieved your requirement by using the custom toolbar item feature of grid. Custom toolbar is used to create your own toolbar items in toolbar
Please refer to the below code snippet,
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" …… >
… <ToolbarSettings ShowToolbar="True" ToolbarItems="excelExport,wordExport,pdfExport"> <CustomToolbarItem> <ej:CustomToolbarItem TemplateID="#Refresh" /> </CustomToolbarItem> </ToolbarSettings> </ej:Grid>
….
<script id="Refresh" type="text/x-jsrender">
<a class="e-toolbaricons refresh" /> CSV export </script> <style type="text/css" class="cssStyles">
.refresh { background-image: url("../Content/images/Add csv-02.png"); } </style> |
Please refer to the below help documentation,
https://help.syncfusion.com/aspnet/grid/toolbar#custom-toolbar-items
Regards,
Pon selva
Hi, thank you for your reply.
I tried this and I get a null reference exception error (object not set) which appears to come from ej.Export.dll
I have enclosed project references, picture or runtime error and the project files for scrutiny.
Please note that the grid is databound and shows data, all fields are bound to datasource.
Many thanks for your help
Rgds, John
Query: I tried this and I get a null reference exception error (object not set) which appears to come from ej.Export.dll
We can see from your code that you are exporting the SQL data source. When exporting the SqlDataSource, you need to retrieve the data from the database using the SqlDataSource's select method and pass the dataSource to the export() server method.
We have already discussed about how to export the Grid when we bind the SQL DataSource in ASP.NET in our Syncfusion Knowledge base.
Please refer to the below KB documentation,
https://www.syncfusion.com/kb/8342/how-to-export-the-grid-when-we-bind-the-sql-datasource-in-asp-net
For null exception: https://www.syncfusion.com/kb/3018/null-exception-while-exporting
If you still facing issue after trying the above method, please provide the following information
The requested information will be helpful to proceed further
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
I have just discovered the 'PrintGrid' option that offers print or PDF Save which is ideal.
Thank you for your help.
John
John,
We are glad to know that the issues have been resolved at your end. Please get back to us for further assistance.
We are marking this ticket as solved.
Regards,
Suganya Gopinath.
Hi, can you please tell me if it is possible to put text next to the "Print" icon when
printing a grid. I am using the following and it works perfectly without any text...
<ToolbarSettings ShowToolbar="True" ToolbarItems="printGrid"></ToolbarSettings>
If I try your previous suggestions (as below) it does not even show the bound grid.
<ToolbarSettings ShowToolbar="True" ToolbarItems="excelExport,wordExport,pdfExport">
<CustomToolbarItem><ej:CustomToolbarItem TemplateID="#Refresh" /></CustomToolbarItem>
</ToolbarSettings>
<script id="Refresh" type="text/x-jsrender">
<a class="e-toolbaricons refresh" />
Print or PDF
</script>
<style type="text/css" class="cssStyles">
.refresh {background-image: url("../Content/images/Add csv-02.png");}
</style>
I don't understand how having ToolbarItems="printGrid" and <CustomToolbarItem> work together.
Thank you for your help.
John
Hi John
Query: If I try your previous suggestions (as below) it does not even show the bound grid.
Based on your query, we suspect that you are not referring to the jsrender script file in your application. If you are using a template in your sample, you should refer to the jsrender script file in the script section.
Please refer to the below help documentation,
https://help.syncfusion.com/js/grid/getting-started#preparing-html-document
Query: I don't understand how having ToolbarItems="printGrid" and <CustomToolbarItem> work together.
We achieved your requirement by using the custom toolbar item feature of grid. Custom toolbar is used to create your own toolbar items in toolbar. Actions for this customized toolbar is defined in the toolbarClick event.
Please refer to the below code snippet,
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" …… >
… <ClientSideEvents ToolbarClick="onToolBarClick" />
<ToolbarSettings ShowToolbar="True" ToolbarItems="excelExport,wordExport,pdfExport"> <CustomToolbarItem> <ej:CustomToolbarItem Text="Print" TemplateID="#Refresh" /> </CustomToolbarItem> </ToolbarSettings> </ej:Grid>
…. <script type="text/javascript"> function onToolBarClick(args) { if (args.itemName == "Print") //here print using print method $("# OrdersGrid ").ejGrid("print"); } </script> <script id="Refresh" type="text/x-jsrender">
<a class="e-toolbaricons refresh" /> Print or PDF </script> <style type="text/css" class="cssStyles">
.refresh { background-image: url("../Content/images/Add csv-02.png"); //Here you need to add the print icon } </style> |
We have already discussed same in our help documentation. Please refer to the below help documentation,
https://help.syncfusion.com/aspnet/grid/toolbar#custom-toolbar-items
If you still facing issue after trying the above method, please provide the following information
The requested information will be helpful to proceed further