Solved

Month drop down changing the day.

Posted on 2006-06-29
17
231 Views
Last Modified: 2010-04-16
Hi experts, I little help if i may.

I am using some code I found on the following web site:

http://www.syncfusion.com/faq/aspnet/search/257.aspx

I am using the c# example, my problem is that when I select a month from the drop down it changes the selected day in the calendar control and not the month.

Can any one see why, and if so, how to fix.

Regards

Wayne
0
Comment
Question by:watherton
  • 9
  • 8
17 Comments
 
LVL 5

Expert Comment

by:t_itanium
ID: 17007825
i think that there is a difference between the format in the calender and the format you r using in the code....

one type of format: DD/MM/YY
the other maybe : MM/DD/YY..

so there will be a conflict between day and month..

cheers
Tarek
0
 

Author Comment

by:watherton
ID: 17007857
hi tarek,

thank you for the quick response, however all i've done is cut and paste the code from the site, does it work for you?

Wayne
0
 
LVL 5

Accepted Solution

by:
t_itanium earned 100 total points
ID: 17007976
i think here is the problem..:

DateTime dtNewDate;
 
dtNewDate =DateTime.Parse (Int16.Parse(ddlMonth.SelectedItem.Text) + "/1/" + Int16.Parse( ddlYear.SelectedItem.Text));
 
Calendar1.TodaysDate=dtNewDate ;

here you are using the format : MM/DD/YYYY
and your calender may be using : DD/MM/YYYY
and thus cosidering the day as month


good luck
 
0
 

Author Comment

by:watherton
ID: 17008034
ok stepped through the code and the dtNewDate is 09/01/2006 00:00:00, which does look like things are the wrong way around.

do you happen to know the code to switch it to 01/09/2006?

0
 
LVL 5

Expert Comment

by:t_itanium
ID: 17008073
instead of playing with the format..
try to use  

dtNewDate=DateTime.Now;
dtNewDate.AddMonth(difference between the dropdownlist and DateTime.Now);

cheers
0
 

Author Comment

by:watherton
ID: 17008122
sorry, not following, all I want to do is select a month from the drop down and then set the calendar to be that month. not sure what you mean by difference between, can you show an example
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 17008181
i mean if your current month is june... 06  

and you chose from the drop to  be august....
then the difference between them is 2...

just add this difference to DateTime.Now.AddMonth(difference)

it will add 2 to 06 and it will change to august..

did you get it..
0
 

Author Comment

by:watherton
ID: 17008217
sorry t, this is all new stuff to me, do have code example
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:t_itanium
ID: 17008234
DateTime dtNewDate=DateTime.Now;

int diff=int.Parse(ddlMonth.SelectedItem.Text)-int.Parse(DateTime.Now.ToString());

dtNewDate.AddMonth(diff);
Calendar1.TodaysDate=dtNewDate ;

cheers
 

 
0
 

Author Comment

by:watherton
ID: 17008250
system DateTime does not contain a definition for AddMonth
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 17008270
sorry

dtNewDate=DateTime.Now.AddMonth(diff);
0
 

Author Comment

by:watherton
ID: 17008284
getting there, get the following after selecting a month, my months are string 01,02,03 etc

System.FormatException: Input string was not in a correct format
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 17008305
can you trace the code using breakpoints and f11 to see where is the incorrectformat ??
0
 

Author Comment

by:watherton
ID: 17009255
it's failing on this line
int diff=int.Parse(ddlMonth.SelectedItem.Text)-int.Parse(DateTime.Now.ToString());
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 17009760
instead of DateTime.Now.ToString()

use DateTime.Now.Month.TOString()

cheers
0
 

Author Comment

by:watherton
ID: 17009947
great stuff thanks for your help
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 17011435
welcome ;)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now