如何禁用 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/