Can't hide column in datagrid

Discussion in 'ASP .Net' started by enak, Oct 31, 2003.

  1. enak

    enak Guest

    I populate a datagrid by setting the datasource to a
    datatable. I then, bind them. After that I try to hide the
    last column but am not able to. I get an error message.

    Here is my code:

    Me.dgReport.DataSource = ds.Tables("tFirst")
    Me.dgReport.DataBind()
    Me.dgReport.Columns(7).Visible = False

    Here is the error that I get:

    System.ArgumentOutOfRangeException: Index was out of
    range. Must be non-negative and less than the size of the
    collection. Parameter name: index


    If I take the last line of code out then the page
    displayes as expected except for the last column. I tried
    to hide column 3 but got the same result.

    After the Bind command I looked at the Columns.Count
    property and it is 0. Why is this happening and how do I
    fix it?

    Thanks
    enak
     
    enak, Oct 31, 2003
    #1
    1. Advertising

  2. enak

    Sunil TG Guest

    You should write
    Me.dgReport.Tables(0).Columns(7).Visible = False
    Then it will work fine.

    Sunil TG


    >-----Original Message-----
    >I populate a datagrid by setting the datasource to a
    >datatable. I then, bind them. After that I try to hide

    the
    >last column but am not able to. I get an error message.
    >
    >Here is my code:
    >
    > Me.dgReport.DataSource = ds.Tables("tFirst")
    > Me.dgReport.DataBind()
    > Me.dgReport.Columns(7).Visible = False
    >
    >Here is the error that I get:
    >
    >System.ArgumentOutOfRangeException: Index was out of
    >range. Must be non-negative and less than the size of the
    >collection. Parameter name: index
    >
    >
    >If I take the last line of code out then the page
    >displayes as expected except for the last column. I tried
    >to hide column 3 but got the same result.
    >
    >After the Bind command I looked at the Columns.Count
    >property and it is 0. Why is this happening and how do I
    >fix it?
    >
    >Thanks
    >enak
    >
    >.
    >
     
    Sunil TG, Oct 31, 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. jonnylbluejeans
    Replies:
    4
    Views:
    5,919
    Rick Spiewak
    Jul 24, 2003
  2. Thanh Nu
    Replies:
    2
    Views:
    1,000
    Thanh-Nu
    Oct 30, 2003
  3. Raterus
    Replies:
    1
    Views:
    1,652
    =?Utf-8?B?UmV6YSBOYWJp?=
    Feb 20, 2004
  4. Keithb
    Replies:
    2
    Views:
    1,202
  5. George Viveiros

    How can I hide a column in my Datagrid

    George Viveiros, Oct 29, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    130
    John Soulis [MSFT]
    Oct 30, 2003
Loading...

Share This Page