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.
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
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
GrdGrid.DataSource = dtGrid Setgridhead()
For lngrow = 0 To GrdGrid.Rows.Count - 1 lfFillItmItemsDet(GrdGrid, lngrow, GrdGrid.Rows(lngrow).Cells("poditmid").Value)Next
gpSetGrdSno(GrdGrid, "sno")
dtGrid.AcceptChanges()
=========================
Private Function lfFillItmItemsDet(ByRef grd As TMGrid, ByVal lngrow As Long, ByVal itmid As Long) Dim DtTemp As New DataTable
Try SQLSTR = " SELECT * " & _ " FROM mstitem " & _ " WHERE itmid = " & itmid & _ " AND approve = 'Y'" TMMain.GfFillTableForRead(DtTemp, SQLSTR)
If DtTemp.Rows.Count > 0 Then grd.Rows(lngrow).Cells("itmcode").Value = DtTemp.Rows(0)("itmcd") grd.Rows(lngrow).Cells("poditmdesc").Value = DtTemp.Rows(0)("itmdesc") grd.Rows(lngrow).Cells("itmloccd").Value = DtTemp.Rows(0)("itmloccd")End If
Catch ex As Exception gfShowERRMsg(lblFrmCaption.Text, ex.Message, Nothing, texButtonStyleConstants.bsOk, ex)End Try
End Function
While Running this Code object reference not set to an instance of an object Error Coming.
If i Trace to Find out line,that time it Executed Perfectly.
(Note : It is not Because of sending Grid as Reference,also error coming for get the values For Grid Rows within the For Loop EX: From ID we get Description for particular Column)
If You Know Any answer Regarding this, Please Reply