Click here to Skip to main content
12,255,255 members (58,782 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#3.0 C# 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 20:49pm
siva575598
Edited 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,
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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 6 May 2013
Copyright © CodeProject, 1999-2016
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