views:

312

answers:

3

I have a gridview. Its datasource is set as follows. dtTable is a datable in which the values for the table will be retrieved. But when setting dtTable as datasource I get an error "Object reference not set to an instance of an object". What may be the reason for this?

gridview.Datasource = dtTable
gridview.Databind()
+1  A: 

Make sure that dtTable has the records you need. This error usually means that dtTable is null.

Rick J
+1  A: 

Take a look at where the dtTable variable is initialised. Is it coming back as Nothing? Maybe you are getting another error that is being ignored. Probably the dtTable is the cause of the problem.

1800 INFORMATION
A: 

You won't get a null reference exception if the data table is null, you will get one if the gridview is null. That's assuming that one of these two lines are actually generating the exception.

Phaedrus