如何根据用户选择的下拉列表将日历日期设置为不可选择? [英] How to set the calendar dates unselectable accordingly to the dropdownlist users select?
问题描述
如何根据用户选择的DropDownList中的名称将日历日期设置为不可选择?
换句话说,DropDownList中的每个名称都将设置不同的不可选择日期,我尝试使用以下代码执行我的程序,但似乎无法正常工作.
我该怎么办?
How do i set the calendar dates unselectable accordingly to the name in the DropDownList the users select?
In other words, each name in the DropDownList will have different unselectable dates set and i tried to use the following codes to execute my program but it seems to be not working.
How do i do so?
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedItem.Text == "WeddingPlanner1")
{
if (e.Day.Date.Month == 7 || e.Day.Date.Month == 9 || e.Day.Date.Month == 12)
{
if (e.Day.Date.Day == 5 || e.Day.Date.Day == 14 || e.Day.Date.Day == 18)
{
e.Day.IsSelectable = false;
e.Cell.ForeColor = System.Drawing.Color.Black;
e.Cell.BackColor = System.Drawing.Color.White;
e.Cell.Font.Bold = true;
}
}
}
推荐答案
为DropDownList1
设置AutoPostBack
为true
setAutoPostBack
true forDropDownList1
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" >
之后,将您的代码移至日历控件的Day渲染事件中
after that, move your code in to Day render event of your calendar control
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (DropDownList1.SelectedItem.Text == "WeddingPlanner1")
{
if (e.Day.Date.Month == 7 || e.Day.Date.Month == 9 || e.Day.Date.Month == 12)
{
if (e.Day.Date.Day == 5 || e.Day.Date.Day == 14 || e.Day.Date.Day == 18)
{
e.Day.IsSelectable = false;
e.Cell.ForeColor = System.Drawing.Color.Black;
e.Cell.BackColor = System.Drawing.Color.White;
e.Cell.Font.Bold = true;
}
}
}
}
您知道如何添加上述事件吗?
转到日历控件的属性,然后转到事件选项卡,找到DayRender并双击它.
You know how to add above event?
go to properties of your calendar control and then go to events tab and find the DayRender and double click on it.
这篇关于如何根据用户选择的下拉列表将日历日期设置为不可选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!