c# - Hide a column in webgrid?

How can I hide a column in a webgrid? I should be able to access those values from the grid but the user should not be able to see the column in the grid. There is no condition, but completely I want to hide those columns

My column is

grid.Column(header: "Phone")

2 Answers

  1. Franklin- Reply


    Probably the easiest way is to just use some CSS/jQuery where 'TABLECLASS' is the name of your table's class:

    table.TABLECLASS th:first-child, table td:first-child {
        display: none;

    I do not think there is a way to do this via the built in WebGrid.

  2. Fred- Reply


    If you want to hide the 2nd column, for instance:

      $("#yourGridId th:nth-child(2)").hide();
      $("#yourGridId td:nth-child(2)").hide();

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>