DataGrid's DataBind() error

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
 
D

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?
 
C

Craig Deelsnyder

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.
 
D

Dee

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
 
E

Elton Wang

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top