动态显示/隐藏webgrid中的列标题

时间:2013-07-01 11:11:24

标签: razor webgrid

我正在使用WebGrid显示动态选择的表列我想要隐藏未选中的列。我可以动态隐藏列标题吗?

我正在使用关注webgrid。

    <div>   
    @{    
    var grid = new WebGrid(Model.oTravelReadyEntities);
    grid.Pager(WebGridPagerModes.NextPrevious);
    @grid.GetHtml(tableStyle: "WebGrid",
    headerStyle: "Header",
    alternatingRowStyle: "alt",
    columns: grid.Columns(


    grid.Column("Var_AssoId", "Var_AssoId", canSort: true, format: @<text>            
    @if(item.Var_AssoId == 0){@Html.Hidden("Var_AssoId", "Var_AssoId");        
    }                                                                                               
    else{ @item.Var_AssoId}</text>),

    grid.Column("Var_AssociateName", "Var_AssociateName", format: @<text>
    @if (item.Var_AssociateName == null)
    {@Html.Hidden("Var_AssociateName", "Var_AssociateName")}
    else
    {@item.Var_AssociateName}</text>),


    grid.Column("Var_Grade", "Var_Grade", format: @<text>
    @if (item.Var_Grade == null)
    {@Html.Hidden("Var_Grade", "Var_Grade")}
    else
    {@item.Var_Grade}</text>),

    grid.Column("Char_VirtualPool", "Char_VirtualPool", format: @<text>
    @if (item.Char_VirtualPool == null)
    {@Html.Hidden("Char_VirtualPool", "Char_VirtualPool")}
    else
    {@item.Char_VirtualPool}</text>),

    grid.Column("Var_VirtualPoolCatagory", "Var_VirtualPoolCatagory", format: @<text>
    @if (item.Var_VirtualPoolCatagory == null)
    {@Html.Hidden("Var_VirtualPoolCatagory", "Var_VirtualPoolCatagory")}
    else
    {@item.Var_VirtualPoolCatagory}</text>),

    grid.Column("Char_VisaUtilization", "Char_VisaUtilization", format: @<text>
    @if (item.Char_VisaUtilization == null)
    {@Html.Hidden("Char_VisaUtilization", "Char_VisaUtilization")}
    else{@item.Char_VisaUtilization}</text>),

    grid.Column("Var_Deparment", "Var_Deparment", format: @<text>
    @if (item.Var_Deparment == null){@Html.Hidden("Var_Deparment", "Var_Deparment")}
    else{@item.Var_Deparment}</text>),

    grid.Column("Var_Vertical", "Var_Vertical", format: @<text>
     @if (item.Var_Vertical == null){@Html.Hidden("Var_Vertical", "Var_Vertical")}
    else{@item.Var_Vertical}</text>),

    grid.Column("Var_AccountName", "Var_AccountName", format: 
    @<text>@if (item.Var_AccountName == null){
    @Html.Hidden  ("Var_AccountName", "Var_AccountName")}
    else{@item.Var_AccountName}</text>),

    </div>

我想在某些Condition上隐藏Column标头。如何使用条件语句隐藏Column标题?

1 个答案:

答案 0 :(得分:0)

以下是有条件地显示/隐藏我觉得有用的网页列的一种方法:MVC 3 Webgrid - how do you hide columns you do not want to be visible?