WebGrid not exporting data if data is manually populated.

1 reply. Last post: September 23, 2013 10:50 PM by Yudi
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback
Jim DresserMember

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 Dresser
Rochester 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>




All times are GMT -5. The time now is 3:48 PM.
Previous Next