我怎样才能把它应用到ListView之前筛选数据源 [英] How can I filter a DataSource before applying it to a ListView
问题描述
我有一个实体的数据源,这是我需要它传递到ListView之前进行过滤。这里是未经过滤的版本(伟大工程):
的DataContext DB =新的DataContext();
ListView1.DataSource = db.Cars;
ListView1.DataBind();
我想了解如何只能选择蓝色(字段/属性/行数据库)的汽车,并通过只是那些汽车到ListView。我一直在这个努力的变化:
字符串selectedColor =蓝色;
DataContext的DB =新的DataContext();
ListView1.DataSource = db.Cars.Any(M => m.Cars.color == selectedColor);
ListView1.DataBind();
应该不是这个更喜欢,
ListView1.DataSource = db.Cars.Where(车= GT; car.Color == selectedColor);
您 db.Cars.Any(M = GT; m.Cars.color == selectedColor)
[更正:应m.Color而不是m.Cars。颜色,如果你想要的方式]语句中使用它,如果你的汽车收藏有至少一个车颜色值作为该selectedColor将返回true。
I have an Entity datasource, which I need to filter before passing it to the ListView. Here is the unfiltered version (works great):
DataContext db = new DataContext();
ListView1.DataSource = db.Cars;
ListView1.DataBind();
I'm trying to understand how to select only the Cars that are blue (a field/property/row in the database), and pass just those Cars to the ListView. I've been trying variations on this:
String selectedColor = "blue";
DataContext db = new DataContext();
ListView1.DataSource = db.Cars.Any(m => m.Cars.color == selectedColor);
ListView1.DataBind();
Shouldn't this be more like,
ListView1.DataSource = db.Cars.Where(car => car.Color == selectedColor);
Your db.Cars.Any(m => m.Cars.color == selectedColor)
[Correction: should be m.Color instead of m.Cars.Color if you wanted to use it by the way] statement will return true if in your Cars collection there's at least one car with color value as that of the selectedColor.
这篇关于我怎样才能把它应用到ListView之前筛选数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!