我有一个system.Linq.Enumerable.WhereListIterator,它返回的值如下图所示 [
但是当我将此添加到列表然后添加到下拉数据源时,它不起作用
请帮忙
这是我的代码
using (var dr = db.ExecuteDataReader("GetDealersWithDiscount", CommandType.StoredProcedure, param))
{
while (dr.Read())
{
dealers.Add(new Dealer
{
Name = Convert.ToString(dr["dealer_name"]),
Adress = Convert.ToString(dr["dealer_address"]),
Zipcode = Convert.ToString(dr["dealer_zip_code"]),
Image = Convert.ToString(dr["dealer_name"]),
Manufacturer = Convert.ToString(dr["manufacturer_id"])
});
}
}
string[] zipcodes = strzipcode.Split(',');
List<Dealer> filterList = new List<Dealer>();
filterList.Add(new Dealer
{
Zipcode = txtZipCode.Text.Trim()
});
for (int x = 0; x < zipcodes.Length-1; x++)
{
filterList.Add(new Dealer
{
Zipcode = zipcodes[x]
});
}
var filteredFileSet = dealers.Where(i => filterList.Contains(i));
dtlSanPham.DataSource = filteredFileSet.ToList();
dtlSanPham.DataBind();
答案 0 :(得分:0)
您似乎只在filterList
创建新的经销商,只有一个邮政编码,然后将它们与dealers
列表中包含Zipcodes的经销商以及其他信息进行比较(这意味着他们将从不匹配。)
不要将经销商与经销商进行比较,而是尝试创建一个List<string>
只是拉链码,并对其进行过滤。在where子句中,您需要引用ZipCode类的字符串属性或覆盖类中的ToString()
以显示它。
How to override ToString()
Where(i => filterList.Contains(i.ZipCode.Value));
或
Where(i => filterList.Contains(i.ZipCode.ToString()));
string[] zipcodes = strzipcode.Split(',');
List<string> filterList = new List<string>();
filterList.Add(txtZipCode.Text.Trim());
zipcodes.ForEach(zipCode => {
filterList.Add(zipCode);
})
var filteredFileSet = dealers.Where(i => filterList.Contains(i.ZipCode.Value));
dtlSanPham.DataSource = filteredFileSet.ToList();
dtlSanPham.DataBind();