﻿<?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 - getting page error</title><link>http://www.intersoftsolutions.com/Community/WebGrid/getting-page-error/</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>getting page error</title><link>http://www.intersoftsolutions.com/Community/WebGrid/getting-page-error/</link><pubDate>Thu, 21 Jul 2011 02:40:23 GMT</pubDate><dc:creator>yudi</dc:creator><description>&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt"&gt;A hierarchical WebGrid binds to Customers-Orders-Order Details table of Northwind database through InitializeDataSource server-side event as shown in the following code.&lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="font-family: 'consolas', 'courier new'; color: blue; font-size: 9pt"&gt;protected void&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;WebGrid1_InitializeDataSource(&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; color: blue; font-size: 9pt"&gt;object&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;sender, ISNet.WebUI.WebGrid.&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; color: #2b91af; font-size: 9pt"&gt;DataSourceEventArgs&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;e)
{&lt;/span&gt;
    &lt;span style="font-family: 'consolas', 'courier new'; color: #2b91af; font-size: 9pt"&gt;dsNorthwind&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;ds =&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; color: blue; font-size: 9pt"&gt;new&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; color: #2b91af; font-size: 9pt"&gt;dsNorthwind&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;();

    dsNorthwindTableAdapters.&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; color: #2b91af; font-size: 9pt"&gt;CustomersTableAdapter&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;daCustomers =&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; color: blue; font-size: 9pt"&gt;new&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;dsNorthwindTableAdapters.&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; color: #2b91af; font-size: 9pt"&gt;CustomersTableAdapter&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;();
    dsNorthwindTableAdapters.&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; color: #2b91af; font-size: 9pt"&gt;OrdersTableAdapter&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;daOrders =&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; color: blue; font-size: 9pt"&gt;new&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;dsNorthwindTableAdapters.&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; color: #2b91af; font-size: 9pt"&gt;OrdersTableAdapter&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;();
    dsNorthwindTableAdapters.&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; color: #2b91af; font-size: 9pt"&gt;Order_DetailsTableAdapter&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;daOrderDetails =&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; color: blue; font-size: 9pt"&gt;new&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;dsNorthwindTableAdapters.&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; color: #2b91af; font-size: 9pt"&gt;Order_DetailsTableAdapter&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;();

    daCustomers.Fill(ds.Customers);
    daOrders.Fill(ds.Orders);
    daOrderDetails.Fill(ds.Order_Details);

    e.DataSource = ds;
}&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt"&gt;When the InitializeDataSource event is invoked and the codes inside the InitializeDataSource event are executed, WebGrid will proceed to invoke the PrepareDataBinding event automatically. In this event, all the columns structure is populated by using following code.&lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="font-family: 'consolas', 'courier new'; color: blue; font-size: 9pt"&gt;protected void&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;WebGrid1_PrepareDataBinding(&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; color: blue; font-size: 9pt"&gt;object&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;sender, ISNet.WebUI.WebGrid.&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; color: #2b91af; font-size: 9pt"&gt;DataSourceEventArgs&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;e)
{&lt;/span&gt;
    &lt;span style="font-family: 'consolas', 'courier new'; color: blue; font-size: 9pt"&gt;if&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;(!IsPostBack)
        WebGrid1.RetrieveHierarchicalStructure();
}&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt"&gt;Following code is used to set the DefaultValue property of ‘OrderID’ column of Orders table to a value, for example, -1.&lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;WebGrid1.GetTableByName(&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; color: #a31515; font-size: 9pt"&gt;"Orders"&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;).Columns.GetNamedItem(&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; color: #a31515; font-size: 9pt"&gt;"OrderID"&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt"&gt;).DefaultValue = (-1).ToString();&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt"&gt;If the code is added in InitializeLayout server-side event, an exception will occur (“Object reference not set to an instance of an object”). After debugged, I found that &lt;em&gt;WebGrid1.GetTableByName(“Orders”)&lt;/em&gt; returns null.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt"&gt;InitializeLayout event is originally designed to let developers programmatically configure static WebGrid's behavior, appearance, look and feel, styles etc. No dynamic objects or data related settings should be placed here especially if those objects are created during runtime.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt"&gt;Based on WebGrid life cycle, the InitializeLayout event will be called before InitializeDataSource event and PrepareDataBinding event, hence it won’t be possible for grid to obtain the table’s name and column’s name. The exception occur because the tables and columns population are created –using RetrieveHierarchicalStructure– at PrepareDataBinding.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui','sans-serif'; color: #1f497d; font-size: 9pt"&gt;Moving the code to PrepareDataBinding event solve the issue on this particular sample. I am willing to advise you further but in order to do so I would need you to elaborate on your specific scenario and possibly give us a running simple sample and step-by-step guide that we can use to observe the problematic behavior.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>getting page error</title><link>http://www.intersoftsolutions.com/Community/WebGrid/getting-page-error/</link><pubDate>Wed, 20 Jul 2011 10:25:33 GMT</pubDate><dc:creator>schau</dc:creator><description>&lt;p&gt;Hi Yudi,&lt;/p&gt;
&lt;p&gt;thanks for the quick response.  I tried your suggestion, but I'm still getting the same error. &lt;/p&gt;</description></item><item><title>getting page error</title><link>http://www.intersoftsolutions.com/Community/WebGrid/getting-page-error/</link><pubDate>Wed, 20 Jul 2011 05:36:39 GMT</pubDate><dc:creator>yudi</dc:creator><description>&lt;p&gt;&lt;span style="font-family: 'segoe ui', 'sans-serif'; color: #1f497d; font-size: 9pt"&gt;Please try to assign the DefaultValue property in the PrepareDataBinding server-side event instead of InitializeLayout server-side event.&lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt; color: blue;"&gt;protected void&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt;"&gt;WebGrid1_PrepareDataBinding(&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt; color: blue;"&gt;object&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt;"&gt;sender, ISNet.WebUI.WebGrid.&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt; color: #2b91af;"&gt;DataSourceEventArgs&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt;"&gt;e)
{&lt;/span&gt;
    &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt; color: blue;"&gt;if&lt;/span&gt; &lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt;"&gt;(!IsPostBack)
        WebGrid2.RetrieveHierarchicalStructure();
        
    WebGrid2.GetTableByName(&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt; color: #a31515;"&gt;"t_log_entry2"&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt;"&gt;).Columns.GetNamedItem(&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt; color: #a31515;"&gt;"log_entry_id"&lt;/span&gt;&lt;span style="font-family: 'consolas', 'courier new'; font-size: 9pt;"&gt;).DefaultValue = (-1).ToString();
}&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui', 'sans-serif'; color: #1f497d; font-size: 9pt"&gt;It seems that assigning the property in the InitializeLayout server-side event is too early.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: 'segoe ui', 'sans-serif'; color: #1f497d; font-size: 9pt"&gt;Hope this helps.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>getting page error</title><link>http://www.intersoftsolutions.com/Community/WebGrid/getting-page-error/</link><pubDate>Tue, 19 Jul 2011 16:25:42 GMT</pubDate><dc:creator>schau</dc:creator><description>&lt;h2&gt;&lt;i&gt;Object reference not set to an instance of an object.&lt;/i&gt; &lt;/h2&gt;
&lt;p&gt;&lt;span style="font-family: arial, helvetica, geneva, sunsans-regular, sans-serif "&gt;&lt;b&gt;Description: &lt;/b&gt;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. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Exception Details: &lt;/b&gt;System.NullReferenceException: Object reference not set to an instance of an object.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Source Error:&lt;/b&gt; &lt;br /&gt;&lt;br /&gt;
&lt;table width="100%" bgcolor="#ffffcc"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&lt;pre&gt;Line 281:
Line 282:    Protected Sub WebGrid2_InitializeLayout1(sender As Object, e As ISNet.WebUI.WebGrid.LayoutEventArgs) Handles WebGrid2.InitializeLayout
&lt;span style="color: red"&gt;Line 283:        WebGrid2.GetTableByName("t_log_entry2").Columns.GetNamedItem("log_entry_id").DefaultValue = -1
&lt;/span&gt;Line 284:
Line 285:&lt;/pre&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="font-family: verdana"&gt;Source File: &lt;/span&gt;&lt;/b&gt;C:\Users\administrator.SYSTEMS\Documents\Visual Studio 2010\WebSites\WebSite5\LogBookEntries.aspx.vb&lt;b&gt;&lt;span style="font-family: verdana"&gt; &amp;nbsp;&amp;nbsp; Line: &lt;/span&gt;&lt;/b&gt;283 &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="font-family: verdana"&gt;Stack Trace:&lt;/span&gt;&lt;/b&gt; &lt;br /&gt;&lt;br /&gt;
&lt;table width="100%" bgcolor="#ffffcc"&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;&lt;pre&gt;[NullReferenceException: Object reference not set to an instance of an object.]
   LogBookEntries.WebGrid2_InitializeLayout1(Object sender, LayoutEventArgs e) in C:\Users\administrator.SYSTEMS\Documents\Visual Studio 2010\WebSites\WebSite5\LogBookEntries.aspx.vb:283
   ISNet.WebUI.WebGrid.WebGrid.OnInitializeLayout(LayoutSet layout) &amp;#43;68
   ISNet.WebUI.WebGrid.WebGrid.OnLoad(EventArgs e) &amp;#43;79
   System.Web.UI.Control.LoadRecursive() &amp;#43;74
   System.Web.UI.Control.LoadRecursive() &amp;#43;146
   System.Web.UI.Control.LoadRecursive() &amp;#43;146
   System.Web.UI.Control.LoadRecursive() &amp;#43;146
   System.Web.UI.Control.LoadRecursive() &amp;#43;146
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) &amp;#43;2207
&lt;/pre&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;I get the above error when I try to load the page.  my webgrid is using sqldatasource and it is set to "t_log_entry2" table.  Please help.&lt;/p&gt;</description></item></channel></rss>