Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Datagrid column count = 0??

Reply
Thread Tools

Datagrid column count = 0??

 
 
Kris Rudin
Guest
Posts: n/a
 
      11-10-2003
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,Duratio n,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!
--
Kris Rudin, MS, MCP
Aurora Consulting Group, Inc.


 
Reply With Quote
 
 
 
 
Jos
Guest
Posts: n/a
 
      11-11-2003
Kris Rudin wrote:
> 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,Duratio n,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".

> What am I not understanding, here?
>
> Thanks!


--

Jos


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Column count / Access GridView Column after DataBind Finn Stampe Mikkelsen ASP .Net 4 08-20-2010 07:25 PM
bind a dropdown in a column in a datagrid based on the dropdown value selected in another column of the datagrid. vishnu ASP .Net 1 03-25-2006 01:24 PM
DataGrid.Column.Count is empty? SK ASP .Net Building Controls 2 02-23-2005 12:34 PM
how do i access a dropdownlists selected value in a datagrid edititemtemplate column from the selectedindexchanged event of another dropdownlist in a datagrid edititemtemplate column Dave M ASP .Net Datagrid Control 0 12-14-2004 11:53 AM
I am adding a new row to the datagrid dynamically but if i use the Count property of Item it is not showing the count of the new rows being added Praveen Balanagendra via .NET 247 ASP .Net 2 06-06-2004 07:16 AM



Advertisments