我想从datarow检索日期,并根据datarow中的日期进行比较。但是它有错误声明String未被识别为有效的DateTime。 This is the error example screenshot
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
DataRow[] rows = socialEvents.Select(
String.Format(
"Date >= #{0}# AND Date < #{1}#",
e.Day.Date.ToShortDateString(),
e.Day.Date.AddDays(1).ToShortDateString()
)
);
foreach (DataRow row in rows)
{
System.Web.UI.WebControls.Image image;
image = new System.Web.UI.WebControls.Image();
image.ToolTip = row["Description"].ToString();
e.Cell.BackColor = Color.Wheat;
}
}
private void BuildSocialEventTable()
{
// to simulate a database query
socialEvents = new DataTable();
socialEvents.Columns.Add(new DataColumn("Date", typeof(DateTime)));
socialEvents.Columns.Add(new DataColumn("Description", typeof(string)));
DataRow row;
row = socialEvents.NewRow();
row["Date"] = DateTime.Now.AddDays(-5);
row["Description"] = "Holiday";
socialEvents.Rows.Add(row);
}