[英]how to select only current and upcoming dates in asp.net
I am using calendar control in asp.net. 我在asp.net中使用日历控件。 When the user select the date it will be displayed in the textbox. 当用户选择日期时,它将显示在文本框中。 This is the code that I used for that: 这是我用于此的代码:
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
TextBox1.Text = Calendar1.SelectedDate.ToString("dd/MM/yy");
}
But I want to make only the current and upcoming dates to be selectable. 但是我只想选择当前日期和即将到来的日期。 When the user select the past date, I want to display a error message. 当用户选择过去的日期时,我想显示一条错误消息。 How can I do this? 我怎样才能做到这一点?
You need to handle DayRender
event. 您需要处理DayRender
事件。
ASPX: ASPX:
<asp:Calendar ID="Calendar1" runat="server" ondayrender="Calendar1_DayRender"> </asp:Calendar>
CodeBehind : disable's past days CodeBehind:禁用过去的日子
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date.CompareTo(DateTime.Today) < 0)
{
e.Day.IsSelectable = false;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.