Friday, March 13, 2009

Asp calendar DayRender event.

Hi,

Here is the asp:calendar DayRender event example:



protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
string fontWeight = "normal";
if (isThereEvent(e.Day.Date))
fontWeight = "bold";

string color = "black";
if (e.Day.IsOtherMonth)
color = this.Calendar1.OtherMonthDayStyle.ForeColor.Name;

e.Cell.Text = String.Format("<a href="http://www.blogger.com/Default.aspx?day=%7B0:d%7D" style="text-decoration: none;">{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;
}

No comments:

Post a Comment