我正在使用以下函数加载gridview以形成
private DataClasses1DataContext db_cooperations = new DataClasses1DataContext();
private int numberOfObjectsPerPage = 20;
private int CurrentPageIndex = 1;
Func<IEnumerable<cooperations>, IEnumerable<cooperations>> ordering = t => t.OrderBy(i => i.name);
private void daftarKoperasi_Load(object sender, EventArgs e)
{
GetData(CurrentPageIndex);
dataGridProperty();
}
private void GetData(int page)
{
page = page - 1;
db_cooperations.Log = Console.Out;
var query = (from c in ordering(db_cooperations.cooperations)
select new { c.id, c.name, c.phone, c.email, c.city })
.Skip(numberOfObjectsPerPage * page).Take(numberOfObjectsPerPage).ToList();
dataGridView1.DataSource = query ;
}
然后我想根据name搜索数据,同时过滤city。任何线索我应该进一步做什么?
更新
所以我更新我的代码如下
private void GetData(int page)
{
page = page - 1;
db_cooperations.Log = Console.Out;
var query = (from c in ordering(db_cooperations.cooperations)
select new { c.id, c.name, c.phone, c.email, c.city })
.Skip(numberOfObjectsPerPage * page).Take(numberOfObjectsPerPage).ToList();
if (String.IsNullOrEmpty(searchTxt.Text) == false)
{
query.Where(c => c.name.ToLower().Contains(searchTxt.Text.ToLower()));
}
if (cityCB.SelectedIndex > -1)
{
query.Where(c => c.city.ToLower().Equals(cityCB.Text.ToLower()));
}
dataGridView1.DataSource = query ;
}
但它仍然不起作用