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 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.
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.
[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
Please try calling wdgEntries.Rows.Clear() befor databind and let me know if this fixes the problem. Thanks!
Wow, I was sure I had tried that before, but it must not have been in the proper sequence; once I put the rows.clear before the databind it began working perfectly!
Thanks, Alex!
P.S. Is this a bug in WebDataGrid, or is this just something we need to do before a databind?