asp.net - 禁用 asp 上的 future 日期 :calendar control

标签 asp.net calendar

如何禁用 asp:calendar 控件上的 future 日期?

例如,今天是 2013 年 10 月 22 日,我想禁用 10 月 23 日之后的日期, 并在当前日期时重新​​启用它们。

最佳答案

您将需要使用 DayRender 方法。

C# 代码隐藏

    public void Calendar1_DayRender(object o, DayRenderEventArgs e)
            {


                e.Cell.BackColor = System.Drawing.Color.Empty;
                e.Cell.ForeColor = System.Drawing.Color.DarkRed;

                //if the days are not part of the current month
                if (e.Day.IsOtherMonth)
                {  
                    e.Cell.Text = "";
                }
             }

然后在日历中,您需要放置

ASP

<asp:Calendar ID="Calendar1" runat="server" Height="145px" Width="77px" OnDayRender="Calendar1_DayRender"></asp:Calendar>

将 OnDayRender="Calendar1_DayRender"添加到日历控件。

希望这有帮助!

编辑:我读错了。但是,如果您只想“启用”当天而不是其他日期,那么这将起作用..

代码隐藏

public void Calendar1_DayRender(object o, DayRenderEventArgs e)
        {


            e.Cell.BackColor = System.Drawing.Color.Empty;
            e.Cell.ForeColor = System.Drawing.Color.DarkRed;

            if (e.Day.IsToday)
            {
                e.Cell.BackColor = System.Drawing.Color.Blue;
            }
            else
            {
                e.Cell.Text = "";
            }
        }

关于asp.net - 禁用 asp 上的 future 日期 :calendar control,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19517481/

相关文章:

android - 警报管理器未在 android 中的确切时间触发警报

c# - 在为存储过程设置参数时,我可以在 new SqlParameter 的构造函数中设置 TypeName 吗?

c# - ASP.NET MVC 5 - 重定向到具有文化的同一页面

asp.net - 使用apache服务器和mysql数据库部署ASP.NET MVC

java - 使用 AlarmManager 设置不同时区的闹钟

javascript - Angular 2。 Angular 日历事件单元详细信息模板

c# - 如何在自定义 HtmlHelper 中使用 Html.TextAreaFor() 方法?

c# - 单击按钮刷新 asp.net 页面

Java Calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY),它会向后滚动,向前滚动还是未知?

android - 自动将事件添加到 Android 默认日历