Datagrid column count = 0??

Discussion in 'ASP .Net Datagrid Control' started by Kris Rudin, Nov 10, 2003.

  1. Kris Rudin

    Kris Rudin Guest

    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!
    --
    Kris Rudin, MS, MCP
    Aurora Consulting Group, Inc.
     
    Kris Rudin, Nov 10, 2003
    #1
    1. Advertising

  2. Kris Rudin

    Jos Guest

    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,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".

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


    --

    Jos
     
    Jos, Nov 11, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Green Start Button

    DataGrid.Items.Count and DataGrid Paging...

    Green Start Button, Aug 4, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    5,837
    agravar
    Aug 2, 2006
  2. Finn Stampe Mikkelsen

    Column count / Access GridView Column after DataBind

    Finn Stampe Mikkelsen, Aug 19, 2010, in forum: ASP .Net
    Replies:
    4
    Views:
    3,241
    Finn Stampe Mikkelsen
    Aug 20, 2010
  3. efelnavarro09
    Replies:
    2
    Views:
    954
    efelnavarro09
    Jan 26, 2011
  4. SK

    DataGrid.Column.Count is empty?

    SK, Feb 17, 2005, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    236
    MattC
    Feb 23, 2005
  5. Christopher Calhoun

    Datagrid Column Count HELP

    Christopher Calhoun, Jan 29, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    106
    Christopher Calhoun
    Jan 29, 2004
Loading...

Share This Page