Mohsin Mohsin - 1 year ago 61
ASP.NET (C#) Question

show month in calendar control based on value of dropdownlist

what is the method to select the month name from dropdownlist and then show the month in calender control ive tried so much but no success

enter image description here

picture is attached for better understanding

Answer Source

You can set the calendar's VisibleDate property in code to show the appropriate month, for example:

<asp:DropDownList runat="server" ID="ddlMonth" AutoPostBack="true" OnSelectedIndexChanged="SetCalendarVisibleDate">
    <asp:ListItem Text="January" Value="1" />
    <asp:ListItem Text="February" Value="2" />
    <asp:ListItem Text="March" Value="3" />
    <asp:ListItem Text="April" Value="4" />
    <asp:ListItem Text="May" Value="5" />
    <asp:ListItem Text="June" Value="6" />
    <asp:ListItem Text="July" Value="7" />
    <asp:ListItem Text="August" Value="8" />
    <asp:ListItem Text="September" Value="9" />
    <asp:ListItem Text="October" Value="10" />
    <asp:ListItem Text="November" Value="11" />
    <asp:ListItem Text="December" Value="12" />

<asp:DropDownList runat="server" ID="ddlYear" AutoPostBack="true" OnSelectedIndexChanged="SetCalendarVisibleDate">
    <asp:ListItem Text="2011" Value="2011" />
    <asp:ListItem Text="2012" Value="2012" />
    <asp:ListItem Text="2013" Value="2013" />
    <asp:ListItem Text="2014" Value="2014" />
    <asp:ListItem Text="2015" Value="2015" />

<asp:Calendar runat="server" ID="cal1" />

Then in your code-behind we just need to add the following event handler for the OnSelectedIndexChanged events for the DropDownLists:

protected void SetCalendarVisibleDate(object sender, EventArgs e)
    cal1.VisibleDate = new DateTime(int.Parse(ddlYear.SelectedValue),

An MSDN article on the VisibleDate property:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download