473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

calendar

Hi,

I get the date from a calendar and put it into a text box.

TxtDate.Text = Calendar1.SelectedDate.ToShortDateString();

But I would like to also do it the other way around. That is, convert the
textbox to a calendar date, so that the calendar (when you open it) has the
same value as the date in the textbox.

Thanks for your help

Chris
Nov 17 '05 #1
4 4357
You could do:

Calendar1.SelectedDate = DateTime.Parse( TxtDate.Text );

But take care to catch possible exceptions.

Nov 17 '05 #2
You could do:

Calendar1.SelectedDate = DateTime.Parse( TxtDate.Text );

But take care to catch possible exceptions.

Nov 17 '05 #3
Chris

When you say 'calendar' I have assumed you meant the
System.Windows.Forms.DateTimePicker control.

This code adds the selected date to the text box:

private void Calendar1_ValueChanged(object sender, System.EventArgs e)
{
textBox1.Text = Calendar1.Value.ToShortDateString();
}

but you knew that bit :)

To go the other way you need to put some code in the controls 'Enter' event:

private void Calendar1_Enter(object sender, System.EventArgs e)
{
try
{
// set the date to be the date in the text box
char[] sep = {'/'};
string[] tokens = textBox1.Text.Split(sep);
int day = int.Parse(tokens[0]);
int month = int.Parse(tokens[1]);
int year = int.Parse(tokens[2]);

DateTime date = new DateTime(year, month, day);
Calendar1.Value = date;
}
catch
{
Calendar1.Value = DateTime.Now;
}
}

This is pretty crude and will obviously only work with dates in the
format 'day/month/year' using a '/' as a seperator but it should give
you a good start.

Hope this helps :)

Martin

--------------------------------------
- Martin Stickley : MCP C#, ASP .NET -
--------------------------------------
chris wrote:
Hi,

I get the date from a calendar and put it into a text box.

TxtDate.Text = Calendar1.SelectedDate.ToShortDateString();

But I would like to also do it the other way around. That is, convert the
textbox to a calendar date, so that the calendar (when you open it) has the
same value as the date in the textbox.

Thanks for your help

Chris

Nov 17 '05 #4
Does Microsoft ever think of the way to make datetime working better?
I always have different time each time I work with datetime.

"Martin" <ma*************@btinternet.com> wrote in message
news:d2**********@sparta.btinternet.com...
Chris

When you say 'calendar' I have assumed you meant the
System.Windows.Forms.DateTimePicker control.

This code adds the selected date to the text box:

private void Calendar1_ValueChanged(object sender, System.EventArgs e)
{
textBox1.Text = Calendar1.Value.ToShortDateString();
}

but you knew that bit :)

To go the other way you need to put some code in the controls 'Enter'
event:

private void Calendar1_Enter(object sender, System.EventArgs e)
{
try
{
// set the date to be the date in the text box
char[] sep = {'/'};
string[] tokens = textBox1.Text.Split(sep);
int day = int.Parse(tokens[0]);
int month = int.Parse(tokens[1]);
int year = int.Parse(tokens[2]);

DateTime date = new DateTime(year, month, day);
Calendar1.Value = date;
}
catch
{
Calendar1.Value = DateTime.Now;
}
}

This is pretty crude and will obviously only work with dates in the format
'day/month/year' using a '/' as a seperator but it should give you a good
start.

Hope this helps :)

Martin

--------------------------------------
- Martin Stickley : MCP C#, ASP .NET -
--------------------------------------
chris wrote:
Hi,

I get the date from a calendar and put it into a text box.

TxtDate.Text = Calendar1.SelectedDate.ToShortDateString();

But I would like to also do it the other way around. That is, convert the
textbox to a calendar date, so that the calendar (when you open it) has
the same value as the date in the textbox.

Thanks for your help

Chris

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sugapablo | last post by:
Can someone recommend a very simple script to produce a web calendar? I just want something where I can select a month and year and it produces a very basic HTML table, 7 columns across, one...
2
by: cg_news | last post by:
In short, what I am trying to do is, based on a date, calculate the week of year (as described in ISO 8601), then calculate the first and last date in this week period and return them in the format...
2
by: Caesar Augustus | last post by:
First, let me start by saying my asp.net experience is still in it's infancy so please bare with me as I try to explain my situation. I have created a single page that with the use of many...
0
by: R.A.M. | last post by:
Hello, I need to implement popup calendar in ASP.NET application. I created a button opening popup calendar on 'master' page: <asp:Button ID="Calendar" runat="server" Text=Calendar"...
1
by: R.A.M. | last post by:
Hello, I need to implement popup calendar in ASP.NET application. I created a button opening popup calendar on 'master' page: <asp:Button ID="Calendar" runat="server" Text=Calendar"...
0
by: GV | last post by:
Hi all, New to developing in VS 2005 ASP 2.0 Trying to have a easy pop calender for a button on a web page. I keep getting a error message in IE6 that says: Line 69 Char 3 Error:...
3
by: thorpk | last post by:
I posted this problem earlier in the month and some one decided it was better to change the subject and ask a completely different question. I am therefore reposting. I am hoping some one can...
0
by: mathewgk80 | last post by:
HI all, I am having popup calendar Javascript code. But i dont know how it is connecting to asp.net code.. I am using asp.net,c#.net and also using 3tier architecture with master page.... I...
4
by: gubbachchi | last post by:
Hi all, Please anybody help me solve this problem. I am stuck up with this from past 2 weeks. I am developing an application where, when the user selects date from javascript datepicker and enters...
1
by: abhishekbrave | last post by:
The code below is opening a calendar on mouse over in the same window. I need the calendar to be opened in new window. Have to fulfill this requirement urgentely so posting the whole code here. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.