How to remove/make invisible autogenerated gridview column

Discussion in 'ASP .Net' started by Julia B, Oct 2, 2008.

  1. Julia B

    Julia B Guest

    Hi

    I've just moved from asp.net 1.1 to 2.0 so am new to gridviews and have a
    problem.

    I've got a gridview on a form in a web layer project. It has an
    objectdatasource object which calls a method in a class in a seperate data
    layer project.Therefore the columns are autogenerated. The problem I've got
    is that the data that fills the gridview has an "id" column which I don't
    want to display but I do want to use programmatically. I've tried hiding &
    removing the column but, wherever I put the code, I get an "Argument out of
    range" error. My code is:

    Me.UserGridView.Columns.RemoveAt(1)

    I've tried this in Page Load, Page LoadComplete etc etc.... to no avail.
    There is no code on the page to populate the GridView, it's all done through
    VisualStudio's ObjectDataSource object properties.

    Any clues on how to resolve this would be greatly appreciated.

    Thanks
    Julia
    Julia B, Oct 2, 2008
    #1
    1. Advertising

  2. You can do it in RowCreated event. Don't remove columns, just hide them with
    e.Item.Cells(1).Visible = false.

    In any case, put "id" in DataKeyNames, otherwise you won't find in in
    postbacks.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin


    "Julia B" <> wrote in message
    news:...
    > Hi
    >
    > I've just moved from asp.net 1.1 to 2.0 so am new to gridviews and have a
    > problem.
    >
    > I've got a gridview on a form in a web layer project. It has an
    > objectdatasource object which calls a method in a class in a seperate data
    > layer project.Therefore the columns are autogenerated. The problem I've
    > got
    > is that the data that fills the gridview has an "id" column which I don't
    > want to display but I do want to use programmatically. I've tried hiding &
    > removing the column but, wherever I put the code, I get an "Argument out
    > of
    > range" error. My code is:
    >
    > Me.UserGridView.Columns.RemoveAt(1)
    >
    > I've tried this in Page Load, Page LoadComplete etc etc.... to no avail.
    > There is no code on the page to populate the GridView, it's all done
    > through
    > VisualStudio's ObjectDataSource object properties.
    >
    > Any clues on how to resolve this would be greatly appreciated.
    >
    > Thanks
    > Julia
    Eliyahu Goldin, Oct 2, 2008
    #2
    1. Advertising

  3. Julia B

    Julia B Guest

    Thanks for this. Unfortunately I still get the same error.

    I had to use e.Row.Cells(1).Visible = False

    Item is not a member of the argument.

    Any ideas where I'm going wrong?

    Julia
    "Eliyahu Goldin" wrote:

    > You can do it in RowCreated event. Don't remove columns, just hide them with
    > e.Item.Cells(1).Visible = false.
    >
    > In any case, put "id" in DataKeyNames, otherwise you won't find in in
    > postbacks.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    >
    >
    > "Julia B" <> wrote in message
    > news:...
    > > Hi
    > >
    > > I've just moved from asp.net 1.1 to 2.0 so am new to gridviews and have a
    > > problem.
    > >
    > > I've got a gridview on a form in a web layer project. It has an
    > > objectdatasource object which calls a method in a class in a seperate data
    > > layer project.Therefore the columns are autogenerated. The problem I've
    > > got
    > > is that the data that fills the gridview has an "id" column which I don't
    > > want to display but I do want to use programmatically. I've tried hiding &
    > > removing the column but, wherever I put the code, I get an "Argument out
    > > of
    > > range" error. My code is:
    > >
    > > Me.UserGridView.Columns.RemoveAt(1)
    > >
    > > I've tried this in Page Load, Page LoadComplete etc etc.... to no avail.
    > > There is no code on the page to populate the GridView, it's all done
    > > through
    > > VisualStudio's ObjectDataSource object properties.
    > >
    > > Any clues on how to resolve this would be greatly appreciated.
    > >
    > > Thanks
    > > Julia

    >
    >
    Julia B, Oct 2, 2008
    #3
    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. Susan Geller
    Replies:
    1
    Views:
    401
    =?Utf-8?B?U3VyZXNo?=
    Mar 2, 2004
  2. jax
    Replies:
    2
    Views:
    1,956
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Apr 2, 2004
  3. Michael Chong

    DataGrid Column Make Invisible

    Michael Chong, Oct 15, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    3,469
    Michael Chong
    Oct 16, 2004
  4. =?Utf-8?B?U3RldmU=?=

    Remove AutoGenerated DataGrid Column??

    =?Utf-8?B?U3RldmU=?=, Dec 15, 2005, in forum: ASP .Net
    Replies:
    9
    Views:
    1,871
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Dec 17, 2005
  5. Andy B
    Replies:
    5
    Views:
    574
    Andy B
    May 29, 2008
Loading...

Share This Page