只是想问一下如何将dataTable绑定到asp.net日历我试过但是在页面加载时失败我创建sude代码到exp lane我想要什么
private void populateCalendar(DataTable dt)
{
foreach (var row in dt.Rows)
{ //if dates are in dt chage background color to red
if(Calendar1.date)
}
}
答案 0 :(得分:0)
据我了解你的问题,我试图解决你的问题
步骤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是日期集合