[Exercise] Enter your birthday (year/month/day) #2

Source: Internet
Author: User

Original article exit http://www.dotblogs.com.tw/mis2000lab/archive/2013/06/10/calendar_visibledate_birthday_dropdownlist.aspx

[Exercise] Enter your birthday (year/month/day) #2 -- the time of the Calendar control jumps back to five years or ten years ago? -- TodaysDate and VisibleDate

 


Previous Article:[Exercise]Enter your birthday (Year/Month/Day)--Calendar(Calendar)Control time jump, one jump back five years, ten years ago?-- TodaysDateProperties,VisibleDateAttribute

Http://www.dotblogs.com.tw/mis2000lab/archive/2011/05/30/calendar_todaysdate.aspx

 

This exercise can be considered「 Previous set 」Ch.3Calendar Control.

Add the following features:

 

"Born"YearIf you want to include the one hundred-year option

We can't add sub-options by ourselves. It must be completed by writing programs.

 

How do I control the year?

SeeSystem. DateTimeThere are many available methods.

For example. AddYear ()Method, You can use-1 to subtract one year. Please referHttp://msdn.microsoft.com/zh-tw/library/system.datetime.addyears.aspx

 

For (int I = 0; I <101; I ++)

{

// = Method 1 =:

// Int myYear =System. DateTime. Now. Year -I;

// DropDownList1.Items. Add (myYear. ToString ());

 

// = Method 2 =:

DropDownList1.Items. Add (System. DateTime. Today. AddYears(-I). ToString ("Yyyy"));

}

 Suggestion: Set System. DateTimeMoveForLoop outside,

Avoid calling the Now () or. AddYear () method for each running cycle to save resources.

 

 

 

Another key point is to "Create a calendar control ".RenderingThat year, that month 」

Use the calendar control'sVisibleDate"AttributeIt is better than the "TodaysDate" attribute.

As mentioned in MSDN:

IfVisibleDateAttributeNot set. The specified date TodaysDate attribute determines which month will be displayed in the Calendar control.

 

// = Method 1 =:

// Calendar1. TodaysDate=New DateTime(Convert. ToInt32 (DropDownList1.SelectedValue), Convert. ToInt32 (DropDownList2.SelectedValue), 1 );

// = Date in DateTime (Year/Month/Day). Only integers are allowed 」.

 

// = Method 2 =:

// *** It is recommended that you use the. VisibleDate attribute instead.

// *** Only the current month is displayedMonth」!

Calendar1. VisibleDate=NewDateTime(Convert. ToInt32 (DropDownList1.SelectedValue), Convert. ToInt32 (DropDownList2.SelectedValue), 1 );

// = Date in DateTime (Year/Month/Day). Only integers are allowed 」.

 

When the. VisibleDate attribute is used, when the month date is not "preset", the screen looks better.

 

 

 

This is a supplementary example of class,

Many "beginners 」ThoughtDo not write programs by yourself

Later, I found that they do not use string functions or date-and time-related functions.

 

It may not be the "Basic if/for/while Syntax" That won't be used. After all, I have learned a little bit in school before.

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.