DataGrid's DataBind() error

  • Thread starter Thread starter Dee
  • Start date Start date
D

Dee

Hi,
I'm working on a sample WebForm proj that accesses an Access database.
There is a desgn-time
DataSet ds1
and a
DataGrid dg.

Page_Load contains 2 lines:
da.Fill(ds1)
dg.DataBind().

I have set the DataSource of dg set to ds1 and DataMemeber to a table
therein.

I get
System.NullReferenceException: "Object reference not set to an instance
of an object"
error when aspnet tries to execute dg.DataBind().

Any help appreciated.
Dee
 
I got the BindData() to work but then the columns I set to display is
completely ignored but
only sometimes.
Is the DataGrid difficult to tame?
 
I got the BindData() to work but then the columns I set to display is
completely ignored but
only sometimes.
Is the DataGrid difficult to tame?

Well, it is pry the largest beast in ASP.NET :) But actually it's not
that bad; we'd need to see some code here to see what's wrong. Mainly the
asp:datagrid code from your aspx and the code where you're binding the
dataset to it. Without that we won't be able to tell if, for example,
AutoGenerateColumns is set to false appropriately, etc.
 
Thanks Craig,
I needed a good ol reboot. Bunch of strange things was happening including
when i made changes in the desgin view the code behind didnt get updated
and irinically when it did it was followed by a "Catastrophic Failure!"
message.
Anyway i dont want to jinx it but its behaving now.
Thanks again.
Dee
 
You can try:

da.Fill(ds1)
dg.DataSource = ds1
' or
dg.DataSource = ds.Tables(0)
' or
dg.DataSource = ds.Tables(0).DefaultView
dg.DataBind()

HTH

Elton Wang
(e-mail address removed)
 
Back
Top