Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I'm making a website in asp.net (C#)and I'm having problems getting the date from the calendar and assigning a value to that date and printing it out in a textbox. I've tried all sorts of things but it just won't go. I'm a severe noob and would really appreciate some help.
My latest attempt looked somewhat like this:

if Calendar1.SelectedDate = ""
textBox1.Text = "";

I tried around with datetime, strings, etc. without any luck.
Help?
Posted

Have a look at the Calendar sample here[^].
Just using SelectedDate as show here[^].
Remember though that this is a server control.
 
Share this answer
 
Try this quick solution for C# Windows Forms:

DateTime selectedDate = Convert.ToDateTime(monthCalendar1.SelectionStart);
textBox1.Text = selectedDate.ToShortDateString();


Test it by putting the code within the monthCalendar1_DateSelected event.


Try this solution for ASP.NET Web Applications:


DateTime selectedDate = Convert.ToDateTime(Calendar1.SelectedDate);
TextBox1.Text = selectedDate.ToShortDateString();


Test by putting the code within the Calendar1_SelectionChanged event.
 
Share this answer
 
Not exactly what i wanted. What I'm to do is have events show in the textbox. For instance if the user's current selection is 28/07/2011 It'll write "meeting friends". Thanks anyway. It gave me a rough idea.
 
Share this answer
 
Comments
Eslam Mostafa 24-Jul-11 2:29am    
what about this solution?
i'm fined a nice solution take it
step1:

your form should contain
1- tow textbox one of them visible=false
2- calender

step2:

//code under calender
TextBox1.Text = Calendar1.SelectedDate.ToShortDateString().ToString();//this textbox visible=false

C#
if (TextBox1.Text == "7/1/2011")
      {
          TextBox2.Text = "meeting";
      }
      else
      {
          TextBox2.Text = TextBox1.Text;
      }


step3:

to fill 30 days use elseif(){}
 
Share this answer
 
Comments
Eslam Mostafa 24-Jul-11 2:32am    
and you can use enum in this case
Thanks. Disn't think of that. Case closed :-)
 
Share this answer
 

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