Hide Columns in GridView?

P

Phil Sandler

Quick question:

Is it possible to use autogeneratecolumns = true and still hide
specific columns based on the column name in the datasource?

Failing that, can it be done by column index?


Thanks,

Phil
 
G

Guest

Hi Phil,

Yes you can, but it's quite *nasty* - you end up with accessing Controls
collection (as you may know, autogenerated fields are not added to the
Columns collection, they are kept in private variable _autoGenFieldProps -
see it for yourself in quick watch window while debuging), Anyway, here's the
mentioned solution:

foreach (TableRow row in list.Controls[0].Controls)
{
row.Cells[IndexOfTheColumnToHide].Visible = false;
}

You can still do it properly, adding columns programatically based on the
datasource (i know it would require a little bit more codding).

Hope this helps
 
E

Eliyahu Goldin

Just note that you can catch autogenerated columns in the grid's ItemCreated
event.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top