iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Using the 2012 R2 version of WebGrid, if I manually populate the WebGrid (instead of binding it to some datasource), the grid can not be exported. I get the "Object reference not set to an instance of an object." error.It doesn't matter how I try to export the Grid (client side, server side, or using the export button at the bottom of the grid).This use to work (in either WebGrid 6 or 7).Please see the attached file. It's a stand-alone webpage where I'm manually putting data into the grid. The page has two buttons on it, on for client side export and one for server side export - neither work.How can I fix this?Thanks,Jim DresserRochester NY
<%@ Page Language="VB" %> <%@ Register Assembly="ISNet.WebUI.WebGrid" Namespace="ISNet.WebUI.WebGrid" TagPrefix="ISWebGrid" %> <script runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If Not Page.IsPostBack Then SetDynInfo() LoadTableInfo() End If End Sub Sub LoadTableInfo() 'now, fill in all the table info.... 'first, create the number of rows in memory Dim y As Int16 = 10 Dim rootRows() As WebGridRow = New WebGridRow(y) {} For I = 0 To 10 rootRows(I) = WebGrid1.RootTable.CreateRow() Next 'put some data into memory rootRows(0).Cells(0).Text = "Hello World" rootRows(0).Cells(2).Text = "2012" rootRows(0).Cells(3).Text = "2013" 'finally, add the rows to the grid, and you are done WebGrid1.RootTable.Rows.AddRange(rootRows) End Sub Sub DropDownList_Table_Changed(ByVal sender As Object, ByVal e As EventArgs) LoadTableInfo() End Sub Private Function SetDynInfo() As DynARInfo Dim dynInfo As New DynARInfo("excel", Server.MapPath("~/TempReports") + "\") dynInfo.IISReportPath = "./TempReports/" dynInfo.DynPageOrientation = PageOrientation.Landscape Return dynInfo End Function Protected Sub ButtonExport_Click(ByVal sender As Object, ByVal e As EventArgs) Dim s As String = Server.MapPath("./TempReports/") Dim file As String = WebGrid1.ExportGrid(New ISNet.WebUI.WebGrid.DynARInfo("excel", Server.MapPath("~/TempReports/"), "admin_analyze")) ' export grid data fileLabel.Text = "Click here to open the file : <a href = '/TempReports/admin_analyze.xls'>[Excel Download]</a>" End Sub </script> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function Button1_onclick() { // retrieves WebGrid's object var WebGrid2 = ISGetObject("WebGrid1"); WebGrid2.ExportGrid("", "EXCEL", "PORTRAIT"); // export grid to excell } </script> </head> <body> <form id="form1" runat="server" style="font-size: 13px;"> <input id="Button1" type="button" value="Export to Excel (Client)" language="javascript" onclick="return Button1_onclick()" /> <asp:Button ID="ButtonExport" runat="server" OnClick="ButtonExport_Click" Text="Export to Excel (server)" /> <asp:Literal ID="fileLabel" runat="server"></asp:Literal> <ISWebGrid:WebGrid ID="WebGrid1" runat="server" Height="300px" UseDefaultStyle="True" DefaultStyleMode="Elegant" RenderingMode="XHTML"> <RootTable> <Columns> <ISWebGrid:WebGridColumn Caption="0" Name="0" Width="130px"> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="1" Name="1" Width="120px"> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="2" Name="2" Width="90px"> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="3" Name="3" Width="80px"> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="4" Name="4" Width="80px"> </ISWebGrid:WebGridColumn> </Columns> </RootTable> <LayoutSettings AllowColumnFreezing="Yes" AllowContextMenu="true" AllowColumnMove="Yes" AllowEdit="No" AllowExport="Yes" AllowGrouping="Yes" AllowSorting="Yes" EditOnClick="True" AllowFilter="Yes" ShowFilterStatus="true" HideColumnsWhenGrouped="Default" FilterBarVisible="false" FreezePaneSettings-AbsoluteScrolling="true" ShowRefreshButton="true"> </LayoutSettings> </ISWebGrid:WebGrid> </form> </body> </html>
Manually populate WebGrid row (instead of binding it to a data source) means that the Grid is operating in unbound mode. Please note that when WebGrid is operating in unbound mode, all data-bound features – such as sorting, grouping, exporting, etc – should not be enabled.
However, there is a workaround to implement such scenario using different approach. Instead of manually populate WebGrid row in LoadTableInfo() method (during Page_Load event), please try to manually populate a data table in InitializeDataSource event (server-side event) of WebGrid and then assign the data table to e.DataSource.
Protected Sub WebGrid1_InitializeDataSource(sender As Object, e As ISNet.WebUI.WebGrid.DataSourceEventArgs) Handles WebGrid1.InitializeDataSource Dim dt As New DataTable() dt.Columns.Add("Column0", GetType(String)) dt.Columns.Add("Column1", GetType(Single)) dt.Columns.Add("Column2", GetType(Single)) dt.Rows.Add("Item1", 0, 100) dt.Rows.Add("Item2", 5, 200) dt.Rows.Add("Item3", 10, 500) e.DataSource = dt End Sub
Please kindly have the attached sample file of WebGrid evaluated on your end and let us hear whether this helps or not.
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname