简体   繁体   English

MVC WebGrid的列宽?

[英]MVC webgrid column width?

Now am working on MVC webgrid. 现在正在开发MVC Webgrid。 I need to set the column width based on the requirement. 我需要根据要求设置列宽。

Grid: 网格:

 @{ 
    var grid = new WebGrid(source: Model.TenantList, rowsPerPage: 11, canPage: true, canSort: false);
        @grid.Table(
        headerStyle: "headerStyle",
        tableStyle: "table table-responsive fixed-column fixed-column table-striped table-hover a-grid",
        alternatingRowStyle: "alternateStyle",
        htmlAttributes: new { id = "tenantgrid" },
        columns: grid.Columns(
        grid.Column("Action", style: "labelcolumn cchk",format:@<text><input class="checkbox cchk" id="assignChkBx" name="assignChkBx" value="@item.Person_Code" type="checkbox" onClick="assignChkBx()" /></text>),
        grid.Column("TitleName"),
        grid.Column("FullName",style: "name-width"),
        grid.Column("Employee_Number"),
        grid.Column("Fathername"),
        grid.Column("Address"),
        grid.Column("EMAILID")
        )
    )
    }

Css: CSS:

.name-width {
        width:500px;
    }

problem is the class is called like this 问题是该类被称为这样

<td class="name-width">AMEER ABOOBACKER</td>

But its not applying my grid. 但是它没有应用我的网格。 I cant find the error. 我找不到错误。 friends give me the solution........ Thanks advance. 朋友给我解决方案........谢谢您。

You can specify a class for each column as you mentioned. 您可以如上所述为每列指定一个类。 The style you have for your table has fixed-column and most probably that's overriding your custom css. 您表的样式具有固定的列,并且很可能覆盖了您的自定义CSS。 You could remove that class (and use below instead) or alternatively you can try adding !important to your css property. 您可以删除该类(并在下面使用),或者尝试将!important添加到css属性。 Below should work as expected. 下面应能按预期工作。

    @grid.GetHtml(tableStyle: "table table-hover",
                      columns:
        grid.Columns
        (
                grid.Column("Property1", "Property1", style: "Large"),
                grid.Column("Property2", "Property2", style: "Small")
                grid.Column("Action", format: @<text>
                    @Html.ActionLink("Edit", "Edit", new { id = item.Id})
                    | @Html.ActionLink("Delete", "Delete", new { id = item.Id })
                </text>, style: "action", canSort: false)))

<style type="text/css">
.Large{
    width: 20%;
}

.Small{
    width: 5%;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM