Object reference error
-
Hi All: I'm trying to dynamically create a datagrid and fill it with XML data. But I get an "Object reference not set to an instance of an object." error when running it. See the code below. What am I missing?
Public Sub CreateDynamicGrid() Dim ds As New DataSet Dim grid As System.Web.UI.WebControls.DataGrid Try 'Place the XML information into a dataset ds.ReadXml("C:\Temp\test.xml") 'The dataset is used as the data source for our newly created datatrid grid grid.DataSource = ds grid.DataBind() 'grid is added to the PlaceHolder PlaceHolder.Controls.Add(grid) Catch ex As Exception Response.Write(ex.Message.ToString) End Try End Sub
Thanks in advance! -
Hi All: I'm trying to dynamically create a datagrid and fill it with XML data. But I get an "Object reference not set to an instance of an object." error when running it. See the code below. What am I missing?
Public Sub CreateDynamicGrid() Dim ds As New DataSet Dim grid As System.Web.UI.WebControls.DataGrid Try 'Place the XML information into a dataset ds.ReadXml("C:\Temp\test.xml") 'The dataset is used as the data source for our newly created datatrid grid grid.DataSource = ds grid.DataBind() 'grid is added to the PlaceHolder PlaceHolder.Controls.Add(grid) Catch ex As Exception Response.Write(ex.Message.ToString) End Try End Sub
Thanks in advance! -
Hi Nicki Which line is thowing the error? Maybe loose the Try/Catch whilst debugging the problem. Cheers Tom
-
Hi All: I'm trying to dynamically create a datagrid and fill it with XML data. But I get an "Object reference not set to an instance of an object." error when running it. See the code below. What am I missing?
Public Sub CreateDynamicGrid() Dim ds As New DataSet Dim grid As System.Web.UI.WebControls.DataGrid Try 'Place the XML information into a dataset ds.ReadXml("C:\Temp\test.xml") 'The dataset is used as the data source for our newly created datatrid grid grid.DataSource = ds grid.DataBind() 'grid is added to the PlaceHolder PlaceHolder.Controls.Add(grid) Catch ex As Exception Response.Write(ex.Message.ToString) End Try End Sub
Thanks in advance! -
Hi Tom: It's this line: --------------------- grid.DataSource = ds --------------------- I don't understand how the dataset could be blank. The file I'm pointing to in the ReadXML method has data in it.
-
You haven't created any DataGrid object, only a reference that can be used for the object.
--- single minded; short sighted; long gone;