﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - WebGrid Enterprise - WebGrid not exporting data if data is manually populated.</title><link>http://www.intersoftsolutions.com/Community/WebGrid/WebGrid-not-exporting-data-if-data-is-manually-populated/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>WebGrid not exporting data if data is manually populated.</title><link>http://www.intersoftsolutions.com/Community/WebGrid/WebGrid-not-exporting-data-if-data-is-manually-populated/</link><pubDate>Mon, 23 Sep 2013 22:50:28 GMT</pubDate><dc:creator>yudi</dc:creator><description>&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;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.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;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.&lt;/span&gt;&lt;/p&gt;&lt;pre&gt;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&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: rgb(31, 73, 125);"&gt;Please kindly have the attached sample file of WebGrid evaluated on your end and let us hear whether this helps or not.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>WebGrid not exporting data if data is manually populated.</title><link>http://www.intersoftsolutions.com/Community/WebGrid/WebGrid-not-exporting-data-if-data-is-manually-populated/</link><pubDate>Mon, 23 Sep 2013 10:38:38 GMT</pubDate><dc:creator>jdresser@idexcorp.com</dc:creator><description>&lt;p&gt;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.&lt;br /&gt;&lt;br /&gt;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).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This use to work (in either WebGrid 6 or 7).&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;How can I fix this?&lt;br /&gt;&lt;br /&gt;Thanks,&lt;br /&gt;Jim Dresser&lt;br /&gt;Rochester NY&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;%@ Page Language="VB" %&amp;gt;
&amp;lt;%@ Register Assembly="ISNet.WebUI.WebGrid" Namespace="ISNet.WebUI.WebGrid" TagPrefix="ISWebGrid" %&amp;gt;
&amp;lt;script runat="server"&amp;gt;
  
  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") &amp;#43; "\")
    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 : &amp;lt;a href = '/TempReports/admin_analyze.xls'&amp;gt;[Excel Download]&amp;lt;/a&amp;gt;"
  End Sub
  
&amp;lt;/script&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;
&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;
&amp;lt;head runat="server"&amp;gt;
  &amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;
  &amp;lt;script type="text/javascript"&amp;gt;
    function Button1_onclick() {
      // retrieves WebGrid's object
      var WebGrid2 = ISGetObject("WebGrid1");
      WebGrid2.ExportGrid("", "EXCEL", "PORTRAIT"); // export grid to excell
    }
  &amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;form id="form1" runat="server" style="font-size: 13px;"&amp;gt;
  &amp;lt;input id="Button1" type="button" value="Export to Excel (Client)" language="javascript" onclick="return Button1_onclick()" /&amp;gt;
  &amp;lt;asp:Button ID="ButtonExport" runat="server" OnClick="ButtonExport_Click" Text="Export to Excel (server)" /&amp;gt;
  &amp;lt;asp:Literal ID="fileLabel" runat="server"&amp;gt;&amp;lt;/asp:Literal&amp;gt;
  &amp;lt;ISWebGrid:WebGrid ID="WebGrid1" runat="server" Height="300px" UseDefaultStyle="True" DefaultStyleMode="Elegant" RenderingMode="XHTML"&amp;gt;
    &amp;lt;RootTable&amp;gt;
      &amp;lt;Columns&amp;gt;
        &amp;lt;ISWebGrid:WebGridColumn Caption="0" Name="0" Width="130px"&amp;gt;
        &amp;lt;/ISWebGrid:WebGridColumn&amp;gt;
        &amp;lt;ISWebGrid:WebGridColumn Caption="1" Name="1" Width="120px"&amp;gt;
        &amp;lt;/ISWebGrid:WebGridColumn&amp;gt;
        &amp;lt;ISWebGrid:WebGridColumn Caption="2" Name="2" Width="90px"&amp;gt;
        &amp;lt;/ISWebGrid:WebGridColumn&amp;gt;
        &amp;lt;ISWebGrid:WebGridColumn Caption="3" Name="3" Width="80px"&amp;gt;
        &amp;lt;/ISWebGrid:WebGridColumn&amp;gt;
        &amp;lt;ISWebGrid:WebGridColumn Caption="4" Name="4" Width="80px"&amp;gt;
        &amp;lt;/ISWebGrid:WebGridColumn&amp;gt;
      &amp;lt;/Columns&amp;gt;
    &amp;lt;/RootTable&amp;gt;
    &amp;lt;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"&amp;gt;
    &amp;lt;/LayoutSettings&amp;gt;
  &amp;lt;/ISWebGrid:WebGrid&amp;gt;
  &amp;lt;/form&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;</description></item></channel></rss>