我該如何與Linq做到這一點? 我試過沒有成功用linq解決DateTime錯誤問題
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;
}
}
我嘗試這一點,但它doen't工作
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();
試圖Convert.ToDateTime(R [ 「日」] )? – jbl 2013-02-27 10:19:16
是的,我只是試試! – 2013-02-27 10:27:57