4

I am new to MVC and I use Webgrid to display some customer values. I need to hide columns together with their headers. How do i do this?

CSS: gridhide { visibility:hidden }
Code: grid.Column("Id", "ID", style: "gridhide"),

ataravati
  • 8,891
  • 9
  • 57
  • 89
Praveen S
  • 650
  • 2
  • 12
  • 35
  • Assuming you meant give the column a class name you're missing the `.` in the `.gridhide` css selector – xec Oct 08 '13 at 11:43

3 Answers3

9

I hide particular column: Please Try This: WEBGRID

grid.Column(null,null, format: @<input type="hidden" name="IDHidden" value="@item.IDHidden"/>),
Praveen S
  • 650
  • 2
  • 12
  • 35
2

I ended up using jQuery to hide the column on the client side. Not ideal but easy to implement. Eg to hide the second column:

$('td:nth-child(2),th:nth-child(2)').hide();

Another option would be to simply not add the column to the grid in the first place like so, as seen here: https://forums.asp.net/post/5850519.aspx

var books = db.Query(sql);
var columns = new List<WebGridColumn>();
columns.Add(new WebGridColumn(){ColumnName = "BookId", Header = "Book Id" });
if(books.Any(b =>b.Price != null)){
    columns.Add(new WebGridColumn(){ColumnName = "Price", Header = "Price" });
}
var grid = new WebGrid(books);
Community
  • 1
  • 1
Matthew Lock
  • 13,144
  • 12
  • 92
  • 130
0

gridhide is a class, define class instead of style in grid.column

Amit
  • 15,217
  • 8
  • 46
  • 68