<p>I know you can put &lt;% if %> statements in the ItemTemplate to hide controls but the column is still there.
You cannot put &lt;% %> statements into the LayoutTemplate which is where the column headings are declared, hence the problem.
Does anyone know of a better way?</p>

[{'answer_id': 70955, 'author': 'Magnus Johansson', 'author_id': 3584, 'author_profile': 'https://Stackoverflow.com/users/3584', 'pm_score': 0, 'selected': False, 'text': "<p>You can always set the column width to 0 (zero) if you don't find a better way.</p>\n"}, {'answer_id': 71015, 'author': 'Jason', 'author_id': 7391, 'author_profile': 'https://Stackoverflow.com/users/7391', 'pm_score': 0, 'selected': False, 'text': '<p>The listview doesn\'t really have a concept of \'column\' since it is intended just to be, well, a list.</p>\n\n<p>I\'m going to assume that you are using databinding to attach a list of \'somethings\' to the ListView. If that is the case then you will just have a list of items and the html in the LayoutTemplate will decide on just how those items are displayed. If you are then talking about creating a table-style array of columns and rows then maybe a DataGrid would be a better choice since this gives much more programmatic control of specific columns.</p>\n\n<p>It may be that you are hoping to create the table layout entirely through CSS, which is an admirable decision <strong>if</strong> it is purely for layout purposes. However, your requirement to specifically hide one column indicates to me that a table is better placed to suit your needs. It\'s fine to use tables for tabular data...IMHO...</p>\n\n<p>If you really do need to use a ListView then you could always try binding against something in your data which determines whether an element should be shown or not, e.g.:</p>\n\n<pre><code>style=\'display: &lt;%#Eval("DisplayStyle") %&gt;;\'\n</code></pre>\n\n<p>Place this code within the html element that you want to control (in the LayoutTemplate). Then in the object you are binding to you would need a property \'DisplayStyle\' which was either set to \'block\' or \'none\'.</p>\n'}, {'answer_id': 71261, 'author': 'Dean Poulin', 'author_id': 5462, 'author_profile': 'https://Stackoverflow.com/users/5462', 'pm_score': 1, 'selected': False, 'text': '<p>The ListView gives you full control about how the data is rendered to the client.  You specify the Layout Template, and give a placeholder which will be where each item is injected.</p>\n\n<p>The output of the below will give you a table, and each item will be a new TR.</p>\n\n<p>Notice the use of runat=\'server\' and <code>visible =\'&lt;%# %&gt;\'</code></p>\n\n<pre><code>&lt;asp:ListView ID="ListView1" runat="server" DataSourceID="MyDataSource" ItemPlaceholderID="itemPlaceHolder"&gt;\n    &lt;LayoutTemplate&gt;\n        &lt;table&gt;\n            &lt;asp:PlaceHolder ID="itemPlaceHolder" runat="server" /&gt;\n        &lt;/table&gt;\n    &lt;/LayoutTemplate&gt;\n    &lt;ItemTemplate&gt;\n        &lt;tr&gt;\n            &lt;td runat="server" id="myCol" visible=\'&lt;%# (bool)Eval("IsSuperCool") %&gt;\'&gt;\n                &lt;%# Eval("SuperCoolIcon") %&gt;\n            &lt;/td&gt;\n            &lt;td&gt;\n                &lt;%# Eval("Name") %&gt;\n            &lt;/td&gt;\n            &lt;td&gt;\n                &lt;%# Eval("Age") %&gt;\n            &lt;/td&gt;\n        &lt;/tr&gt;\n    &lt;/ItemTemplate&gt;\n&lt;/asp:ListView&gt;\n</code></pre>\n'}, {'answer_id': 76264, 'author': 'Dean Poulin', 'author_id': 5462, 'author_profile': 'https://Stackoverflow.com/users/5462', 'pm_score': 5, 'selected': True, 'text': '<p>Here\'s another solution that I just did, seeing that I understand what you want to do:</p>\n\n<p><strong>Here\'s your ASCX / ASPX</strong></p>\n\n<pre><code>    &lt;asp:ListView ID="ListView1" runat="server" DataSourceID="MyDataSource" ItemPlaceholderID="itemPlaceHolder" OnDataBound="ListView1_DataBound"&gt;\n        &lt;LayoutTemplate&gt;\n            &lt;table border="1"&gt;\n                &lt;tr&gt;\n                    &lt;td&gt;Name&lt;/td&gt;\n                    &lt;td&gt;Age&lt;/td&gt;\n                    &lt;td runat="server" id="tdIsSuperCool"&gt;IsSuperCool&lt;/td&gt;\n                &lt;/tr&gt;\n                &lt;asp:PlaceHolder ID="itemPlaceHolder" runat="server" /&gt;\n            &lt;/table&gt;\n        &lt;/LayoutTemplate&gt;\n        &lt;ItemTemplate&gt;\n            &lt;tr&gt;\n                &lt;td&gt;&lt;%# Eval("Name") %&gt;&lt;/td&gt;\n                &lt;td&gt;&lt;%# Eval("Age") %&gt;&lt;/td&gt;\n                &lt;td runat="server" id="myCol" visible=\'&lt;%# (bool)Eval("IsSuperCool") %&gt;\'&gt;true&lt;/td&gt;\n            &lt;/tr&gt;\n        &lt;/ItemTemplate&gt;\n    &lt;/asp:ListView&gt;\n    &lt;asp:ObjectDataSource \n        ID="MyDataSource" \n        runat="server" \n        DataObjectTypeName="BusinessLogicLayer.Thing" \n        SelectMethod="SelectThings"\n        TypeName="BusinessLogicLayer.MyObjectDataSource" /&gt;\n</code></pre>\n\n<p><strong>Here\'s the code behind</strong></p>\n\n<pre><code>/// &lt;summary&gt;\n/// Handles the DataBound event of the ListView1 control.\n/// &lt;/summary&gt;\n/// &lt;param name="sender"&gt;The source of the event.&lt;/param&gt;\n/// &lt;param name="e"&gt;The &lt;see cref="System.EventArgs"/&gt; instance containing the event data.&lt;/param&gt;\nprotected void ListView1_DataBound(object sender, EventArgs e)\n{\n    ListView1.FindControl("tdIsSuperCool").Visible = false;\n}\n</code></pre>\n\n<p>Do whatever you want in the databound.  Because the column is now runat server, and you\'re handling the DataBound of the control, when you do ListView1.FindControl("tdIsSuperCool") you\'re in the Layout template so that works like a champ.</p>\n\n<p>Put whatever business logic that you want to control the visibility of the td and you\'re good.</p>\n'}, {'answer_id': 118758, 'author': 'Fred', 'author_id': 9012, 'author_profile': 'https://Stackoverflow.com/users/9012', 'pm_score': 2, 'selected': False, 'text': '<p>Try Using a Panel and you can turn it on / Off</p>\n\n<pre><code> foreach (ListViewItem item in ListView1.Items)\n {\n     ((Panel)item.FindControl("myPanel")).Visible= False;\n }\n</code></pre>\n'}, {'answer_id': 5425699, 'author': 'yaktipper', 'author_id': 675730, 'author_profile': 'https://Stackoverflow.com/users/675730', 'pm_score': 0, 'selected': False, 'text': '<p>To access the layout template column header text, I made them labels in the template, and did a findcontrol in the prerender of the listview, then made the labels blank text if the column should be "off".  This might not work for your intentions, but for me I still wanted the column space to be used, just appear blank.</p>\n\n<p>The further you go try to make a listview bend over backwards, the more you will wish you used a grid instead.</p>\n'}, {'answer_id': 41151941, 'author': 'jason', 'author_id': 1709186, 'author_profile': 'https://Stackoverflow.com/users/1709186', 'pm_score': 1, 'selected': False, 'text': '<p>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.</p>\n\n<p>Add the following to the header:</p>\n\n<pre><code>&lt;script type="text/javascript" src="Scripts/jquery-1.7.1.min.js" &gt;&lt;/script&gt;\n  &lt;style&gt;\n    .hide {\n      display:none;\n    }\n    .show {\n      display:block;\n    }\n  &lt;/style&gt;\n</code></pre>\n\n<p>For all columns that you want to hide, add a custom property to the td/th.</p>\n\n<pre><code>&lt;th runat="server" data-prop=\'authcheck\'  id="tdcommentsHeader"  &gt;Comments&lt;/th&gt;\n</code></pre>\n\n<p>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.</p>\n\n<p>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.</p>\n\n<pre><code>&lt;asp:HiddenField runat="server" ID="IsAuthorized" Value="false" /&gt;\n</code></pre>\n\n<p>Finally, at the bottom of the page, do:</p>\n\n<pre><code>        &lt;script type="text/javascript"&gt;\n          $(document).ready(function () {\n            var isauth = $("[id=\'IsAuthorized\']").val();\n              if (isauth==="false") {\n              $("[data-prop=\'authcheck\']").addClass(\'hide\');\n              //$("[id*=\'tdcomments\']").addClass(\'hide\'); \n            }\n          });\n      &lt;/script&gt;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/70758', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10186/']