Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 ASP.NET
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: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 5-May-13 21:49pm
siva575556
Edited 5-May-13 22:04pm
v3
Comments
Prasad Khandekar at 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,
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use the SelectionChanged event of the calendar:
 
void Selection_Change(Object sender, EventArgs e)
      {
 
         // update your DropDownList here...
         
      }
 
To update the dropdownlist, use something like this:
 
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
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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];
}
  Permalink  
Comments
siva575 at 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)

  Print Answers RSS
0 OriginalGriff 290
1 Jochen Arndt 165
2 DamithSL 125
3 PIEBALDconsult 110
4 Garth J Lancaster 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 6 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100