Month drop down changing the day.

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
wathertonAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
t_itaniumConnect With a Mentor Commented:
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
 
t_itaniumCommented:
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
 
wathertonAuthor Commented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
wathertonAuthor Commented:
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
 
t_itaniumCommented:
instead of playing with the format..
try to use  

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

cheers
0
 
wathertonAuthor Commented:
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
 
t_itaniumCommented:
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
 
wathertonAuthor Commented:
sorry t, this is all new stuff to me, do have code example
0
 
t_itaniumCommented:
DateTime dtNewDate=DateTime.Now;

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

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

cheers
 

 
0
 
wathertonAuthor Commented:
system DateTime does not contain a definition for AddMonth
0
 
t_itaniumCommented:
sorry

dtNewDate=DateTime.Now.AddMonth(diff);
0
 
wathertonAuthor Commented:
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
 
t_itaniumCommented:
can you trace the code using breakpoints and f11 to see where is the incorrectformat ??
0
 
wathertonAuthor Commented:
it's failing on this line
int diff=int.Parse(ddlMonth.SelectedItem.Text)-int.Parse(DateTime.Now.ToString());
0
 
t_itaniumCommented:
instead of DateTime.Now.ToString()

use DateTime.Now.Month.TOString()

cheers
0
 
wathertonAuthor Commented:
great stuff thanks for your help
0
 
t_itaniumCommented:
welcome ;)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.