Click here to Skip to main content
15,868,340 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends i have a drop down with months and i have a asp calender , I need to show calender with selected month from drop down

eg:
ASP.NET
<asp:DropDownList ID="MonthDropdownlist" runat="server">
<asp:ListItem Text="Select" Value="0">
<asp:ListItem Text="Jan" Value="1">
<asp:ListItem Text="Feb" Value="2">
<asp:ListItem Text="Mar" Value="3">
<asp:ListItem Text="Apr" Value="4">
<asp:ListItem Text="May" Value="5">
<asp:ListItem Text="Jun" Value="6">
<asp:ListItem Text="July" Value="7">
<asp:ListItem Text="Aug" Value="8">
<asp:ListItem Text="Sept" Value="9">
<asp:ListItem Text="Oct" Value="10">
<asp:ListItem Text="Nov" Value="11">
<asp:ListItem Text="Dec" Value="12">            


<asp:Calendar Width="90%" ID="JobsCalender" runat="server" OnDayRender="JobsCalender_DayRender">


[edit]Pre tag added - Amit[/edit]
Posted
Updated 5-May-13 21:04pm
v3
Comments
Prasad Khandekar 6-May-13 3:20am    
Wire a OnSelectedIndexChanged handler for DropDownList with AutoPostBack as true and in the server side handler create a new date which will be the first day of selected month & current year and assign it to selectedDate property of Calendar.

DateTime curDate = DateTime.Today;
DateTime firstDay = new DateTime(curDate.Year, curDate.Month, 1);
JobsCalendar.SelectedDate = furstDay;

Regards,

Use the SelectionChanged event of the calendar:

C#
void Selection_Change(Object sender, EventArgs e)
      {

         // update your DropDownList here...
         
      }


To update the dropdownlist, use something like this:

C#
DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(TheMonthInCalendarControl);
// extract the month from your calendar control and use it to set the dropdownlist SelectedIndex


[The tag on the question said C# so the answer is in C# (rather than Javascript)]

Cheers,
Edo
 
Share this answer
 
v3
Get a asp: calender and a dropdownlist like bellow.........


<asp:calendar id="DateTimePicker" runat="server" onselectionchanged="DateTimePicker_SelectionChanged" xmlns:asp="#unknown">




<asp:dropdownlist id="ddlCalender" runat="server" height="22px" width="260px" xmlns:asp="#unknown">
<asp:listitem selected="True" value="">Select



and write code .aspx.cs page bellow...................

protected void DateTimePicker_SelectionChanged(object sender, EventArgs e)
{
try
{
string month = GetMonthName(DateTimePicker.SelectedDate);

ddlCalender.SelectedItem.Text = month.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
public static string GetMonthName(DateTime givenDate)
{
var formatInfoinfo = new DateTimeFormatInfo();
string[] monthName = formatInfoinfo.MonthNames;
return monthName[givenDate.Month - 1];
}
 
Share this answer
 
Comments
siva575 6-May-13 6:15am    
thanks Rahim


I want to show the calender with selected month from Drop Down list

Can u help me out

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