Does anyone know of a way of hiding a column in an asp.net listview?

前端 未结 7 1747
悲哀的现实
悲哀的现实 2021-01-17 14:45

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

7条回答
  •  借酒劲吻你
    2021-01-17 15:36

    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:

            
    

提交回复
热议问题