Asp.net 在asp:calendar控件上禁用未来日期
如何在Asp.net 在asp:calendar控件上禁用未来日期,asp.net,calendar,Asp.net,Calendar,如何在asp:calendar控件上禁用未来日期 例如,今天是2013年10月22日,我想禁用10月23日以后的日期, 并在当前日期时重新启用它们。您需要使用DayRender方法 C#代码隐藏 public void Calendar1_DayRender(object o, DayRenderEventArgs e) { e.Cell.BackColor = System.Drawing.Color.Empty;
asp:calendar
控件上禁用未来日期
例如,今天是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 = "";
}
}
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
<asp:Calendar ID="Calendar1" runat="server" Height="145px" Width="77px" OnDayRender="Calendar1_DayRender"></asp:Calendar>
您将需要使用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 = "";
}
}
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
<asp:Calendar ID="Calendar1" runat="server" Height="145px" Width="77px" OnDayRender="Calendar1_DayRender"></asp:Calendar>
您可以使用此技巧禁用日历控件中的未来日期
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date > DateTime.Today)
{
e.Day.IsSelectable = false;
}
}
您可以使用此技巧禁用日历控件中的未来日期
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date > DateTime.Today)
{
e.Day.IsSelectable = false;
}
}
@这解决了你的问题吗?这就是你想要的吗?@JbMeris这解决了你的问题吗?这就是你想要的吗?嗨,应该是“如果(e.Day.Date>DateTime.Today)”。谢谢@MattzzHi,应该是“如果(e.Day.Date>DateTime.Today)”。谢谢@Mattzz