Alihuseyn
Alihuseyn

Reputation: 158

I want to change font color of events on calendar

I want to change the font color of all events on HolidayList when I change selection on dates. If there is any event on selected dates, label5 will also change, but I want to change font color of all events when page loaded.

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 = "";
} 

Upvotes: 1

Views: 1292

Answers (1)

Damith
Damith

Reputation: 63065

add DayRender event and you can change font color of holidays as below

 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;
    }

Upvotes: 2

Related Questions