0

只是想问一下如何将dataTable绑定到asp.net日历我尝试但在页面加载时失败了我创建sude代码来explane我想要的

    private void populateCalendar(DataTable dt)
    {

        foreach (var row in dt.Rows)
        {    //if dates are in dt chage background color to red 
            if(Calendar1.date)
        }
    }
4

1 回答 1

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 是日期的集合

于 2013-03-13T17:30:42.140 回答