【发布时间】:2018-04-23 10:30:45
【问题描述】:
我对 ASP.Net 的了解较少。目前,我正在使用 ASP.Net DataGrid 控件,并成功映射了 UI 中的所有源信息。
myDataGrid.DataSource = MyCollectionOfObjects
myDataGrid.DataKeyField = "MyKey"
myDataGrid.DataBind()
现在,问题是,我不希望所有对象都映射到网格中。映射前需要做一些条件过滤。 DataGrid 中是否有任何功能可以让我决定绑定或不绑定某些对象?
1) 一种选择是通过应用所需的过滤将集合 (MyCollectionOfObjects) 映射到仅包含所需对象的新集合,但我目前不希望这样做。
例如,
foreach(var item in MyCollectionOfObjects)
{
if(item.InvalidEntry)
{
// This entry is not needed
}
else
{
// Okay with this entry
}
}
【问题讨论】:
-
您很可能在将您的集合分配为数据源之前使用 LINQ 过滤您的集合。