1

当我更改日期选择时,我想更改 HolidayList 上所有事件的字体颜色。如果选定日期有任何事件,label5 也会发生变化,但我想在页面加载时更改所有事件的字体颜色。

private Hashtable HolidayList; /*Will be kept all holidays in it.*/
protected void Page_Load(object sender, EventArgs e)
{

   HolidayList = Getholiday();
   string date = calendar.TodaysDate.ToShortDateString();
   if (HolidayList[date] != null) Label5.Text = (string)HolidayList[date];
   else Label5.Text = "";
}


private Hashtable Getholiday() 
 {
     Hashtable holiday = new Hashtable();
     holiday["9/5/2013"] = "Mudirin Ad gunu";
     holiday["9/7/2013"] = "Dostumun Ad gunu";
     holiday["10/28/2013"] = "Tetil";
    return holiday;
 }

protected void calendar_SelectionChanged(object sender, EventArgs e)
{
    string date = calendar.SelectedDate.ToShortDateString();

    if (HolidayList[date] != null) Label5.Text = (string)HolidayList[date];
    else Label5.Text = "";
} 
4

1 回答 1

2

添加DayRender事件,您可以更改假期的字体颜色,如下所示

 protected void calendar_DayRender(object sender, DayRenderEventArgs e)
    {
        var day = e.Day.Date.ToString("M/d/yyyy");
        HolidayList = Getholiday();
        if (HolidayList[day] != null)
            e.Cell.ForeColor = System.Drawing.Color.Red;
    }
于 2013-09-05T05:49:17.050 回答