search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Calendar Day Colour

Asked by Yan Xing
11 years ago.

Hello,

I have chosen to use the calendar control along with Daypilot as per the examples given in the package. It all works perfectly but I was wondering if it was possible and if so how can it be achieved to add a style (background color for example) to those days that have events on them?

So if a users visits the page and they see the calendar, those days of the week that have events against them are a different color from everything else.

I hope that makes sense lol.

Many thanks.

Comment posted by Yan Xing
11 years ago.

Sorry I need to be specific. I have tried using the following supplied code from the website however it isn't working.

//Change appearance of the day if there are events there.
private void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
string fontWeight = "normal";
if (isThereEvent(e.Day.Date))
fontWeight = "bold";
string color = "red";
if (e.Day.IsOtherMonth)
color = this.Calendar1.OtherMonthDayStyle.ForeColor.Name;

e.Cell.Text = String.Format("<a href='Default.aspx?day={0:d}' style='color: "
+ color + ";text-decoration:underline; font-weight:"
+ fontWeight + "'>{1}</a>", e.Day.Date, e.Day.Date.Day);
}
private bool isThereEvent(DateTime date)
{
DateTime today = DateTime.Now;
DateTime tomorrow = today.AddDays(1);
DateTime anotherDay = today.AddDays(3);

// there are events today
if ((date.DayOfYear == today.DayOfYear) && (date.Year == today.Year))
return true;

// there are events tomorrow
if ((date.DayOfYear == tomorrow.DayOfYear) && (date.Year == tomorrow.Year))
return true;

// there are events on another day
if ((date.DayOfYear == anotherDay.DayOfYear) && (date.Year == anotherDay.Year))
return true;

return false;
}

The only difference for me is that I am using an SQL Datasource and not a data table. Do I need to alter this code for it to work?

Answer posted by Dan Letecky [DayPilot]
11 years ago.

You need to replace the logic in isThereEvent() with an actual check against your data set. You will need to test for overlaps of the range define by date and date.AddDays(1) with the events.

You can get the dataset from SqlDataSource using Select(). You need to be careful with loading the data - don't load the whole dataset again for each day.

See also the WHERE condition for testing overlaps here:

http://forums.daypilot.org/Topic.aspx/208/daypilot_sql_sample_application

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.