在日历中更改当前星期的背景颜色

问题描述:

我想在日历控件中更改所选日期的当前星期的底色.

I want change the back color of the current week on the selected date in a calendar control.

^ ],然后展开标有日历主题的项目.
Go here [^], and expand the item labeled Calendar Theming.


好吧,这就是它的工作方式.您有一个日历"控件,并且希望当前星期的选定日期"颜色有所不同.

首先,您必须找出startOfWeekendOfWeek

每当选定的日期范围"事件出现在开始"和结束"范围之间时,您必须更改SelectedDayStyle ,否则将使用默认样式进行重置.

Well, this is how it will work. You have a Calendar Control, and you want the current week Selected Date Color something different.

First of all, you have to find out startOfWeek and endOfWeek

When ever the Selected Date Range event coming in between the Start and End of week range, you have to change the SelectedDayStyle , else reset with default style.

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
      {
          if (Calendar1.SelectedDate.Date >= startOfWeek.Date && Calendar1.SelectedDate.Date <= endOfWeek.Date)
          {

              Calendar1.SelectedDayStyle.BackColor = System.Drawing.Color.LightGreen;
          }
          else
          {
              Calendar1.SelectedDayStyle.BackColor = System.Drawing.Color.Gray;
          }
      }



这就是您想要的. :thumbsup:
现在,如何计算我留在您身上的星期开始日期(startOfWeek )和星期结束日期(endOfWeek);)



This is what you were looking for. :thumbsup:
Now, How to calculate the week Start Date (startOfWeek ) and Week End Date (endOfWeek ) I left on you ;)


我找到解决方案对于从星期六到星期五,但是有可能在Java脚本中进行同样的思考
I find solution For select Working Week from Saturday to Friday but it is possible do same think in java script
public void selectWorkingWeek(DateTime CurrentDate)
       {
           DateTime SelectedDate = Calendar1.SelectedDate;
           int Positionday = ReturndayPosition(CurrentDate.DayOfWeek.ToString());
           for (int i = Positionday; i > 0; i--)
           {
               DateTime DT = new DateTime();
               DT = SelectedDate;
               DT= DT.AddDays(-i);
               Calendar1.SelectedDates.Add(DT);
           }

           for (int j = 1; j <= 6-Positionday; j++)
           {
               DateTime DT = new DateTime();
               DT = SelectedDate;
               DT = DT.AddDays(j);
               Calendar1.SelectedDates.Add(DT);
           }
       }

       public int ReturndayPosition(string day)
       {
           int dayPosition = 0;
           switch (day.ToUpper())
           {
               case "SATURDAY": dayPosition = 0; break;
               case "SUNDAY": dayPosition = 1; break;
               case "MONDAY": dayPosition = 2; break;
               case "TUESDAY": dayPosition = 3; break;
               case "WEDNESDAY": dayPosition = 4; break;
               case "THURSDAY": dayPosition = 5; break;
               case "FRIDAY": dayPosition = 6; break;

           }
           return dayPosition;
       }



感谢您的帮助.



Thanks for help.