Jan Hyde <>'s wild thoughts
were released on Fri, 05 May 2006 14:54:48 +0100 bearing the
following fruit:
>"Jason" <>'s wild thoughts were
>released on 5 May 2006 05:29:34 -0700 bearing the following
>fruit:
>
>>How do I hide a column in a GridView in ASP.NET 2.0 when all of the
>>columns are autogenerated based on the datasource? I want to hide the
>>first of three columns, but the following doesn't work:
>>
><SNIP>
>>
>>I need the data in the first column later, so I want it returned - I
>>just don't want to show it in the GridView...
>
>Wouldn't it be easier just to specify the columns you want
>to display and use the DataKeys collection to store your
>other data?
>
Ok, I'm working from memory here so my facts might be a
little off.
Anyhoo - select your datagrid and press f4, find the
property 'DataKeyNames'
Lets say you want to retrieve CustomerID from the database
but don't want to display it in the grid.
Add 'CustomerID' (without quotes) to the DataKeyNames
collection, repeat this for your other fields.
You can retrieve the data with code something like this
GridView1.DataKeys(RowIndex).Item("CustomerID")
Jan Hyde (VB MVP)
--
Man walks into a bookshop, picks up two books and goes to the counter.
He cuts the bottom off one trouser leg and hands it to the assistant
saying, "There's a turn-up for the books."
|