[英]How do I manipulate WebGrids?
I'm using ASP.NET and the MVC pattern. 我正在使用ASP.NET和MVC模式。 I have the following code which I use to style the columns:
我有以下代码用于设置列的样式:
<div id="grid">
@grid.GetHtml(columns: grid.Columns(
grid.Column("Amount", "Amount", canSort: true, style: "column"),
grid.Column("ShelfLife", "ShelfLife", canSort: true, style: "column"),
grid.Column("Size", "Size", canSort: true, style: "column"),
grid.Column("Type", "Type", canSort: true, style: "column"),
grid.Column("Unit", "Unit", canSort: true, style: "column")
))
</div>
I use the following code to load the data for the grid: 我使用以下代码为网格加载数据:
@{
ViewBag.Title = "ListView";
Layout = "~/Views/Shared/_Layout.cshtml";
var grid = new WebGrid(Model, defaultSort: "null");
}
It's probably a long and trivial way of doing this... but I'd like to know how I can manipulate what's in the grid? 这可能是一种漫长而琐碎的方式...但是我想知道我该如何操纵网格中的内容? For example, I'd like to add a button for every row.
例如,我想为每行添加一个按钮。 I'd also like to recolour every second row.
我还想为第二行重新着色。 How would I do this?
我该怎么做?
You can use styles for changing the color of rows in grid and check this link for manipulating the grid. 您可以使用样式来更改网格中行的颜色,并检查此链接以操作网格。
You can define custom css class in a separate css file 您可以在单独的CSS文件中定义自定义CSS类
.comments {
width: 500px;
}
and then assign this class to the corresponding elements: 然后将此类分配给相应的元素:
webGrid.Column(columnName: "TRP_Comments", header: "Comments", style: "comments")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.