设置最小和最大的日历日期?
问题描述:
我有一个环顾四周,再次,找不到如何设置允许在ASP.net日历用VB选择的最小和最大的日期。
I've had a look around, once again and can't find how to set the minimum and maximum dates allowed to be selected on a calendar in ASP.net with VB.
我使用Visual Studio 2010和它只是此刻定期日历控件...
I'm using Visual Studio 2010 and it's just a regular Calendar control at the moment...
目前,我已经看到了这样的话:
At the moment I've seen things like:
Calendar1.DateMin = DateTime.Now
但是,Visual Basic中似乎并不喜欢(也许这是一个C#的东西?)......总之,如果有一种方法可以做到这一点,将是一个很大的帮助!
But Visual Basic doesn't seem to like that (maybe it's a C# thing?)... Anyway, if there's a way to do this it'll be a great help!
答
您需要处理日历的的 的DayRender
事件:
You need to handle the Calendar's DayRender
event:
Private MinDate As Date = Date.MinValue
Private MaxDate As Date = Date.MaxValue
Protected Sub Calendar1_DayRender(sender As Object, e As DayRenderEventArgs)Handles Calendar1.DayRender
If e.Day.Date < MinDate OrElse e.Day.Date > MaxDate Then
e.Day.IsSelectable = False
End If
End Sub
然后你可以在设置例如的Page_Load
:
MinDate = Date.Today
MaxDate = MinDate.AddDays(7)