据我了解您的问题,我尝试将您的查询解决为
步骤 1:在标记中拖放日历控件
<asp:Calendar ID="Calendar1" runat="server" ondayrender="Calendar1_DayRender"></asp:Calendar>
第 2 步:在 Calendar1_DayRender 上
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Date", typeof(DateTime));
dt.Rows.Add(DateTime.Today);
dt.Rows.Add(DateTime.Today.AddDays(10));
dt.Rows.Add(DateTime.Today.AddDays(12));
dt.Rows.Add(DateTime.Today.AddDays(8));
dt.Rows.Add(DateTime.Today.AddDays(6));
dt.Rows.Add(DateTime.Today.AddDays(9));
dt.Rows.Add(DateTime.Today.AddDays(2));
dt.Rows.Add(DateTime.Today.AddDays(1));
dt.Rows.Add(DateTime.Today.AddDays(3));
DateTime date = e.Day.Date;
var query = from row in dt.AsEnumerable()
where row.Field<DateTime>("date") == date
select row;
foreach (var d in query)
{
e.Cell.BackColor = System.Drawing.Color.Red;
}
}
注意:我的示例中使用的 DataTable 是日期的集合