如何根据用户选择的下拉列表将日历日期设置为不可选择? [英] How to set the calendar dates unselectable accordingly to the dropdownlist users select?

查看:235
本文介绍了如何根据用户选择的下拉列表将日历日期设置为不可选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据用户选择的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
set AutoPostBack true for DropDownList1

<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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆