I know you can put <% if %> statements in the ItemTemplate to hide controls but the column is still there. You cannot put <% %> statements into the LayoutTemplate whic
I know it's a very old question, but I'm actually having to do this and think I found a fairly nice way to do it through jquery and css.
Add the following to the header:
For all columns that you want to hide, add a custom property to the td/th.
Comments
I'm advising to use a custom property because, long story short, it can kill a bunch of birds with one stone. You won't even need to change the value for each column, as you would if we based this on the id property.
Next, ensure you have a hidden field that tells lets you know whether or not to hide the column. This can be an asp:HiddenField or any other so long as it's on the form.
Finally, at the bottom of the page, do: