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
Description: 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. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error: Line 281: Line 282: Protected Sub WebGrid2_InitializeLayout1(sender As Object, e As ISNet.WebUI.WebGrid.LayoutEventArgs) Handles WebGrid2.InitializeLayout Line 283: WebGrid2.GetTableByName("t_log_entry2").Columns.GetNamedItem("log_entry_id").DefaultValue = -1 Line 284: Line 285:Source File: C:\Users\administrator.SYSTEMS\Documents\Visual Studio 2010\WebSites\WebSite5\LogBookEntries.aspx.vb Line: 283 Stack Trace: [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) +68 ISNet.WebUI.WebGrid.WebGrid.OnLoad(EventArgs e) +79 System.Web.UI.Control.LoadRecursive() +74 System.Web.UI.Control.LoadRecursive() +146 System.Web.UI.Control.LoadRecursive() +146 System.Web.UI.Control.LoadRecursive() +146 System.Web.UI.Control.LoadRecursive() +146 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
Line 281: Line 282: Protected Sub WebGrid2_InitializeLayout1(sender As Object, e As ISNet.WebUI.WebGrid.LayoutEventArgs) Handles WebGrid2.InitializeLayout Line 283: WebGrid2.GetTableByName("t_log_entry2").Columns.GetNamedItem("log_entry_id").DefaultValue = -1 Line 284: Line 285:
[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) +68 ISNet.WebUI.WebGrid.WebGrid.OnLoad(EventArgs e) +79 System.Web.UI.Control.LoadRecursive() +74 System.Web.UI.Control.LoadRecursive() +146 System.Web.UI.Control.LoadRecursive() +146 System.Web.UI.Control.LoadRecursive() +146 System.Web.UI.Control.LoadRecursive() +146 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
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.
Please try to assign the DefaultValue property in the PrepareDataBinding server-side event instead of InitializeLayout server-side event.
protected void WebGrid1_PrepareDataBinding(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e) { if (!IsPostBack) WebGrid2.RetrieveHierarchicalStructure(); WebGrid2.GetTableByName("t_log_entry2").Columns.GetNamedItem("log_entry_id").DefaultValue = (-1).ToString(); }
It seems that assigning the property in the InitializeLayout server-side event is too early.
Hope this helps.
Hi Yudi,
thanks for the quick response. I tried your suggestion, but I'm still getting the same error.
A hierarchical WebGrid binds to Customers-Orders-Order Details table of Northwind database through InitializeDataSource server-side event as shown in the following code.
protected void WebGrid1_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e) { dsNorthwind ds = new dsNorthwind(); dsNorthwindTableAdapters.CustomersTableAdapter daCustomers = new dsNorthwindTableAdapters.CustomersTableAdapter(); dsNorthwindTableAdapters.OrdersTableAdapter daOrders = new dsNorthwindTableAdapters.OrdersTableAdapter(); dsNorthwindTableAdapters.Order_DetailsTableAdapter daOrderDetails = new dsNorthwindTableAdapters.Order_DetailsTableAdapter(); daCustomers.Fill(ds.Customers); daOrders.Fill(ds.Orders); daOrderDetails.Fill(ds.Order_Details); e.DataSource = ds; }
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.
protected void WebGrid1_PrepareDataBinding(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e) { if (!IsPostBack) WebGrid1.RetrieveHierarchicalStructure(); }
Following code is used to set the DefaultValue property of ‘OrderID’ column of Orders table to a value, for example, -1.
WebGrid1.GetTableByName("Orders").Columns.GetNamedItem("OrderID").DefaultValue = (-1).ToString();
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 WebGrid1.GetTableByName(“Orders”) returns null.
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.
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.
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.
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