问题
I have a webgrid presenting data grouped by weeks. The first grid column contains the weeknumber as seen below in the code example. The last "Summary" column needs to show different content depending on if the rows weeknumber match the current weeknumber or not. Is it possible to use the Weeknumber column value from them Summary column in some way?
@grid.GetHtml(tableStyle: "grid", headerStyle: "head",columns: trainingGrid.Columns(
grid.Column("WeekNumber", "Week"),
.....
grid.Column("Summary", "Sum", format: (item) =>
{ if (***above columns weeknumber == ViewBag.CurrentWeekNo)
{ return "Dolor"
}
else{
return "Sit";
}
}
)
回答1:
In the Column format method's parameter you get the current item as a dynamic object so you can access WeekNumber with normal property syntax:
grid.Column("Summary", "Sum", format: (item) =>
{
if (item.WeekNumber == ViewBag.CurrentWeekNo)
{
return "Dolor";
}
else
{
return "Sit";
}
}
来源:https://stackoverflow.com/questions/8532212/refer-to-an-other-columns-value-in-a-mvc3-razor-webgrid