Hide a column from a Webgrid

Asked

Viewed 357 times

4

Good afternoon.

I have a Webgrid and would like to leave an invisible column. How could I do that?

this is the grid:

@{
Layout = null;
WebGrid grid = new WebGrid(Model);
}


@grid.GetHtml(columns: new [] {
grid.Column("ID_PARAMETER"),
grid.Column("CD_PARAMETER"),
grid.Column("TP_PARAMETER"),
grid.Column("DS_CONTENT"),
grid.Column("DT_UPDATE"),
grid.Column("Edit", format: @<text> @Html.ActionLink("Edit", "EDITMOBILEDATA", 
new{id = item.ID_PARAMETER})</text>),
grid.Column("Delete", format: @<text> @Html.ActionLink("Delete", "DELETEMOBILEDATA",
new {id = item.ID_PARAMETER})</text>)
})

I would like to hide the column ID_PARAMETER.

  • It would be this here Webgrid grid = new Webgrid(Model);

1 answer

3


I have never used this component, but there is a constructor that can be used like this:

WebGrid obj = new WebGrid(Model, columnNames: new[] { "ID_PARAMETER", "CD_PARAMETER", "DS_CONTENT", "DT_UPDATE" });

The reference is here.


EDIT

Apparently it is not enough to specify the column name. You need to define its format manually:

grid.Column("TP_PARAMETER", format: @<input type="hidden" name="TP_PARAMETER" value="@item.TP_PARAMETER"/>),
  • the same one I’m using, I forgot to mention in the question. It would have to hide a column of it?

  • So I took out the column in the constructor. See if it works, please.

  • I tested here, continue showing the ID column

  • @Paulohenrique I updated the answer.

  • 1

    With this format it worked. Thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.