Click here to Skip to main content
15,918,168 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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?

C#
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;
        }
    }
}
Posted
Comments
Sandeep Mewara 8-Jul-12 8:22am    
Dropdownlist eventsargs has a day property? (e.Day?)
kellycx 8-Jul-12 9:02am    
No it doesnt have that is why i could not execute my program as i do not really know how to implement the codes

1 solution

set AutoPostBack true for DropDownList1

C#
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" >


after that, move your code in to Day render event of your calendar control

C#
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;
            }
        }
    }
}


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.
 
Share this answer
 
v3
Comments
kellycx 8-Jul-12 9:57am    
Thank You so much for your solution! I've gotten the result of what i wanted, Thank You so much!! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900