Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2070
Changing data source data after bind
posted

I have a WebDataGrid (new 2009 vol 2 version) on an ASP.NET form (VB.NET). I have the EnableDataViewState turned on so that the table remembers the data between postbacks. However, I have an option on the screen that 'adds' more empty data rows onto the end of the table. In other words:

  • I load the table, set the WebDataGrid datasource to the table, and bind (DataBind) it.
  • After the page is displayed, the user clicks a postback button to tells the system to add some blank rows onto the end of the table.

I then retrieve the database (which I saved in session state), add the required number of rows onto the end of the datatable, and then attempt to rebind the table to the grid, as so:

                    wdgEntries.ClearDataSource()
                    wdgEntries.DataSource = dtEntries
                    wdgEntries.DataBind()

What is happening is that as soon as the DataBind occurs, I get an Object reference not found error, as shown below. Even if I don't add new rows, but change the data and attempt to rebind, I still get this same error. Why is this occuring? It would seem that once I clear the data source and then bind, it should be using the updated data table (and I did check in debug mode - the data table is correct and has rows in it).

Below is the error... Any help/advice? Thanks.

Object reference not set to an instance of an object.

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:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   Infragistics.Web.UI.GridControls.WebDataGrid.InstantiateTemplates() +1290
   Infragistics.Web.UI.GridControls.BaseGrid.EnsureTemplates() +31
   Infragistics.Web.UI.Framework.Data.FlatDataBoundControl.OnPreRender(EventArgs e) +1878
   Infragistics.Web.UI.GridControls.WebDataGrid.OnPreRender(EventArgs e) +37
   System.Web.UI.Control.PreRenderRecursiveInternal() +80
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Control.PreRenderRecursiveInternal() +171
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842