Datagrid column count = 0??

K

Kris Rudin

OK, I'm missing something obvious here...

I have a datagrid that I populate in the code-behind page thusly:
adptr = new OleDbDataAdapter("SELECT
RideDate,RideName,RideDescription,Distance,Duration,AvgMPH,MaxMPH,AvgHR,MaxH
R,Temperature as Temp, Conditions, Comments FROM RideInfo", dbConn);

cmdBldr = new OleDbCommandBuilder(adptr);

adptr.Fill(ds,"RideInfo");



dgRideList.DataSource = ds.Tables["RideInfo"].DefaultView;

dgRideList.DataBind();

But when I then try to access a column:

dgRideList.Columns[1].whatever - it says index out of range. If I do:

dgRideList.Columns.Count

I get 0. What's going on?

The grid displays correctly, but I can't seem to aceess a column
programmatically.

In my ASPX page I have only the grid control defined. No columns. Do I need
to explicitly define the columns? When I tried making bound columns there,
and using the above code, I got all the columns listed twice.

What am I not understanding, here?

Thanks!
 
J

Jos

Kris said:
OK, I'm missing something obvious here...

I have a datagrid that I populate in the code-behind page thusly:
adptr = new OleDbDataAdapter("SELECT
RideDate,RideName,RideDescription,Distance,Duration,AvgMPH,MaxMPH,AvgHR,MaxH
R,Temperature as Temp, Conditions, Comments FROM RideInfo", dbConn);

cmdBldr = new OleDbCommandBuilder(adptr);

adptr.Fill(ds,"RideInfo");



dgRideList.DataSource = ds.Tables["RideInfo"].DefaultView;

dgRideList.DataBind();

But when I then try to access a column:

dgRideList.Columns[1].whatever - it says index out of range. If I do:

dgRideList.Columns.Count

I get 0. What's going on?

Are you sure that you're evaluating dgRideList.Columns.Count
AFTER the DataBind()?
The grid displays correctly, but I can't seem to aceess a column
programmatically.

In my ASPX page I have only the grid control defined. No columns. Do
I need to explicitly define the columns? When I tried making bound
columns there, and using the above code, I got all the columns listed
twice.

When defining the columns at design time, set the Datagrid property
AutoGenerateColumns="False".
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top