code:(页面)
后台:
int preMonth, curMonth, nextMonth;
int[] preMonthArray, curMonthArray, nextMonthArray;
/// <summary>
/// 跟数据库的操作
/// </summary>
/// <param name="year"></param>
/// <param name="month"></param>
/// <returns></returns>
private int[] getArray(int year, int month)
{
int[] array = new int[31];
int i;
for (i = 0; i < 31; i++)
array[i] = 0;
i = 0;
//这里读数据库赋值给arry
while (i>=0&&i<5)
{
array[i++] = i+1;
}
return array;
}
protected void test_DayRender(object sender, DayRenderEventArgs e)
{
CalendarDay day = e.Day; //得到年月日等信息
TableCell cell = e.Cell;
preMonth = day.Date.Month;
curMonth = (preMonth + 1 > 12) ? 1 : (preMonth + 1);
nextMonth = (curMonth + 1 > 12) ? 1 : (curMonth + 1);
curMonthArray = getArray(day.Date.Year, curMonth);
preMonthArray = getArray(day.Date.Year, preMonth);
nextMonthArray = getArray(day.Date.Year, nextMonth);
int j = 0;
if (day.Date.Month.Equals(preMonth))
{
while (preMonthArray[j] != 0)
{
if (day.Date.Day == preMonthArray[j])
{
cell.Controls.Clear();
cell.Controls.Add(new LiteralControl("<a href='#?tid=" + day.Date.Year.ToString() + day.Date.Month.ToString() + day.Date.Day.ToString() + "' style='color:red;text-decoration:underline ' target='_self' >" + day.Date.Day.ToString() + "</a>"));
}
j++;
}
}
else if (day.Date.Month.Equals(nextMonth))
{
while (nextMonthArray[j] != 0)
{
if (day.Date.Day == nextMonthArray[j])
{
cell.Controls.Clear();
cell.Controls.Add(new LiteralControl("<a href='#?tid=" + day.Date.Year.ToString() + day.Date.Month.ToString() + day.Date.Day.ToString() + "' style='color:red ;text-decoration:underline' target='_self' >" + day.Date.Day.ToString() + "</a>"));
}
j++;
}
}
else if (day.Date.Month.Equals(curMonth))
{
while (curMonthArray[j] != 0)
{
if (day.Date.Day == curMonthArray[j])
{
cell.Controls.Clear();
cell.Controls.Add(new LiteralControl("<a href='#?tid=" + day.Date.Year.ToString() + day.Date.Month.ToString() + day.Date.Day.ToString() + "' style='color:red;text-decoration:underline' target='_self' >" + day.Date.Day.ToString() + "</a>"));
}
j++;
}
}
}
protected void test_PreRender(object sender, EventArgs e)
{
Thread t = Thread.CurrentThread;
System.Globalization.CultureInfo c = (System.Globalization.CultureInfo)t.CurrentCulture.Clone();
c.DateTimeFormat.DayNames = new string[] { "日", "一", "二", "三", "四", "五", "六" };
c.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
t.CurrentCulture = c;
}