简体   繁体   English

在asp Calendar控件中以不同颜色显示日期

[英]Display date in different color in asp Calendar control

i am using a calendar control.我正在使用日历控件。 We are getting four different type of date from database and the same will be display on calendar and other date disabled .我们从数据库中获取四种不同类型的日期,日历上将显示相同的日期,其他日期禁用。 The four type of date are四种类型的日期是

a) Today
b) First Schedule
c) Second Schedule
d) Third Schedule

Today will be highlighted with surrounded by green color circle First Schedule as yellow, Second schedule as Green and Third as fourth as Red color .今天将突出显示用绿色圆圈包围第一时间表为黄色,第二时间表为绿色,第三时间表为红色。 当前显示的我的当前日历 . .

The code i have tried as below for我试过的代码如下

<asp:Calendar ID="CalScheduleDays" runat="server"   Height="100%" Width="100%" 
                               BorderWidth="1px" DayNameFormat="Shortest" Font-Names="Verdana" OnDayRender="CalScheduleDays_DayRender" TodayDayStyle-ForeColor="#FF0000" >          </asp:Calendar>


protected void CalScheduleDays_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
        {
                e.Day.IsSelectable = false;                
                CalScheduleDays.SelectedDates.Add(_dates.FirstScheduleDate);
                CalScheduleDays.SelectedDates.Add(_dates.SecondScheduleDate);
                CalScheduleDays.SelectedDates.Add(_dates.ThirdScheduleDate);
            
            if (e.Day.IsSelected)
            {
                  e.Cell.BackColor = System.Drawing.Color.LightGray;
                  e.Cell.ForeColor = System.Drawing.Color.Green;
                  e.Day.IsSelectable = true;
            }

            if (e.Day.IsWeekend)
            {
                e.Cell.BackColor = System.Drawing.Color.LightGray;
                e.Cell.ForeColor = System.Drawing.Color.DarkGray;
                e.Day.IsSelectable = false;
            }
             

    }

Thanks for your help and support for the same.感谢您的帮助和支持。

If you want to highlight by circles only then you can add css in code behind like below如果您只想通过圆圈突出显示,则可以在后面的代码中添加 css,如下所示

if (e.Day.Date == dtFirstSchedule)
 {
    e.Cell.CssClass = "dotYellow";
    e.Day.IsSelectable = true;
 }
else if(e.Day.Date==dtSecondSchedule)
 {
   e.Cell.CssClass = "dotGreen";
   e.Day.IsSelectable = true;
 }
else if(e.Day.Date==dtThirdSchedule)
 {
    e.Cell.CssClass = "dotRed";
    e.Day.IsSelectable = true;
 }
else if(e.Day.Date==DateTime.Now.Date)
 {
   e.Cell.CssClass = "dotGreen";
    e.Day.IsSelectable = true;
 }
else
 {
  //do nothing
 }

And in css class add below css并在 css 类中添加下面的 css

<style>
        .dotRed {
            height: 25px;
            width: 25px;
            background-color:red;
            border-radius: 50%;
        }

       
        .dotGreen {
            height: 25px;
            width: 50px;
            background-color:green;
            border-radius: 100%;
            z-index:-1;
        }

        .dotYellow {
            height: 25px;
            width: 25px;
            background-color:yellow;
            border-radius: 50%;
        }
    </style>

This will display like below这将显示如下

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM