简体   繁体   English

设置日期范围以显示在日历中

[英]set range of date to display in calendar

I have this asp.net calendar control: 我有这个asp.net日历控件:

<asp:Calendar runat="server" ID="calendar" SelectionMode="Day" ondayrender="DateRange" />

and its code behind: 及其背后的代码:

protected void DateRange(object sender, DayRenderEventArgs e)
{
    //do some codes here to set the range of the calendar to display
}

I haven't implemented anything to my DateRange cause I don't know the algorithm of it. 我没有对DateRange实施任何操作,因为我不知道它的算法。

If I want my calendar control to display only specific month and days: 如果我希望日历控件仅显示特定的月份和日期:

Example: Display only the ranges (July 04, 2015 - March 15, 2016) //Nothing follows 示例:仅显示范围(2015年7月4日至2016年3月15日)//没有任何显示

Is it possible to alter the default calendar method to display only the specific months,days above? 是否可以将默认日历方法更改为仅显示上面的特定月份,几天?

Please help, I'm new to calendar event and its built in functions in c#. 请帮忙,我是日历事件的初学者,它是c#中的内置函数。

You can't change what but only how it is displayed and you can make it unselectable: 您不能更改内容,而只能更改其显示方式,并且可以使其变为不可选择状态:

protected void DateRange(object sender, DayRenderEventArgs e)
{
    DateTime rangeStart = new DateTime(2015, 7, 4);
    DateTime rangeEnd   = new DateTime(2016, 3, 15);

    if (e.Day.Date < rangeStart || e.Day.Date > rangeEnd)
    {
        e.Day.IsSelectable = false;
        e.Cell.ForeColor = System.Drawing.Color.Gray;
    }
}

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

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