我怎样才能用 Linq 做到这一点?我试过没有成功
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
DataView view = socialEvents.DefaultView;
view.RowFilter = String.Format(
"Date >= #{0}# AND Date < #{1}#",
Calendar1.SelectedDate.ToShortDateString(),
Calendar1.SelectedDate.AddDays(1).ToShortDateString()
);
if (view.Count > 0)
{
DataGrid1.Visible = true;
DataGrid1.DataSource = view;
DataGrid1.DataBind();
}
else
{
DataGrid1.Visible = false;
}
}
我试试这个,但它不起作用
用户代码未处理 SyntaxErrorException 表达式包含无效名称:[]。
再试一次
var rows = socialEvents.Rows.Cast<DataRow>()
.Where(r => (DateTime)r["Date"] >= Calendar1.SelectedDate.Date &&
(DateTime)r["Date"] <= Calendar1.SelectedDate.AddDays(1))
.ToArray();
view.RowFilter = rows.ToString();