Reputation: 15660
How do i loop through a list of objects and display each one at a column in a grid? for example, i want to do something like:
@grid.GetHtml(
tablestyle:="gridStyle",
headerStyle:="headstyle",
alternatingRowStyle:="alt",
columns:=Grid.Columns(
grid.column("column1", header:="Column1"),
// This is where I want to do something like:
for each entry in ListOfObjects
grid.column(entry.ItemA, header:="ItemA")
next
Upvotes: 0
Views: 919
Reputation: 1332
I don't think this is really what you want, but it's what you asked for:
@{
List<WebGridColumn> cols = new List<WebGridColumn>();
cols.Add(grid.Column("column1", header: "Column1"));
foreach(var entry in ListOfObjects)
{
cols.Add(grid.Column(entry.ItemA, header: "ItemA"));
}
}
@grid.GetHtml(
tablestyle: "gridStyle",
headerStyle: "headstyle",
alternatingRowStyle: "alt-alt",
columns: cols
)
Upvotes: 1