Use dropdownlist in. Net to select a date (vb code)

Source: Internet
Author: User

After reading the C # written by others, I switched it and then changed it to this

 

In addition, there is a code that I wrote to check whether the verification date is legal. It will be followed by VB C # It will only show that it will not be written.

 

 'Determine the leap year ================================< br/> private function checkleap (byval year as integer) as Boolean <br/> If (Year mod 4 = 0) andalso (Year mod 100 <> 0) orelse (Year mod 400 = 0) then <br/> return true <br/> else <br/> return false <br/> end if <br/> end function <br/> 'indicates the end of a leap year = ====================================</P> <p> 'Day of month for binding ========== ================< br/> private sub binddays (byval year as integer, byval month as integer) <br/> dim I as integer <br/> dim Alday as new arraylist () </P> <p> select case month <br/> case 1, 3, 5, 7, 8, 10, 12 <br/> for I = 1 to 31 <br/> Alday. add (I) <br/> next <br/> 'exit select <br/> case 2 <br/> If checkleap (year) then <br/> for I = 1 to 29 <br/> Alday. add (I) <br/> next <br/> else <br/> for I = 1 to 28 <br/> Alday. add (I) <br/> next <br/> end if <br/> 'exit select <br/> case 4, 6, 9, 11 <br/> for I = 1 to 30 <br/> Alday. add (I) <br/> next <br/> 'exit select <br/> end select <br/> dropdownlist_day.datasource = Alday <br/> dropdownlist_day.databind () <br/> end sub <br/> 'end of the number of days of the month for binding ===========================</P> <p> 'drag three dropdownlist dropdownlist_year dropdownlist_month dropdownlist_day to autopostback </P> <p> protected sub page_load (byval sender as object, byval e as system. eventargs) handles me. load </P> <p> dim alyear as new arraylist () <br/> dim I as integer <br/> for I = 1940 to 1992 <br/> alyear. add (I) <br/> next <br/> dim almonth as new arraylist <br/> for I = 1 to 12 <br/> almonth. add (I) <br/> next <br/> if not me. ispostback then <br/> dropdownlist_year.datasource = alyear <br/> dropdownlist_year.databind () <br/> dropdownlist_year.selectedvalue = 1985 <br/> 'binding year <br/> dropdownlist_month.datasource = almonth <br/> dropdownlist_month.databind () <br/> dropdownlist_month.selectedvalue = 6 <br/> 'monthly binding <br/> dim year as integer, month as integer <br/> year = int32.parse (dropdownlist_year.selectedvalue) <br/> month = int32.parse (dropdownlist_month.selectedvalue) <br/> binddays (year, month) <br/> 'binding day <br/> dropdownlist_day.selectedvalue = 15 <br/> end if <br/> end sub </P> <p> protected sub dropdownlist_year_selectedindexchanged (byval sender object, byval e as system. eventargs) handles dropdownlist_year.selectedindexchanged <br/> dim year as integer, month as integer <br/> year = int32.parse (cost) <br/> month = int32.parse (dropdownlist_month.selectedvalue) <br/> binddays (year, month) <br/> end sub </P> <p> protected sub dropdownlist_month_selectedindexchanged (byval sender as object, byval e as system. eventargs) handles dropdownlist_month.selectedindexchanged <br/> dim year as integer, month as integer <br/> year = int32.parse (cost) <br/> month = int32.parse (dropdownlist_month.selectedvalue) <br/> binddays (year, month) <br/> end sub

 

'Date of verification is valid ===================================================< br/>' the 1992 1940 in the table is the year range set by me. <br/> the label_false error message is displayed on the 'page. <br/>' The checkleap function of the leap is used in the above Code. <br/> If (yy> 1992 or (yy <1940 )) or (mm <1) or (MM> 12) Then <br/> label_false.text = "date of birth is incorrect. Please try again! "<Br/> return <br/> end if <br/> select case mm <br/> case 1, 3, 5, 7, 8, 10, 12 <br/> If DD> 31 or DD <1 then <br/> label_false.text = "the birth date is incorrect. Please try again! "<Br/> return <br/> end if <br/> case 4, 6, 9, 11 <br/> If DD> 30 or DD <1 then <br/> label_false.text = "the birth date is incorrect. Please try again! "<Br/> return <br/> end if <br/> case 2 <br/> If checkleap (yy) = false then <br/> If DD> 28 or DD <1 then <br/> label_false.text = "the birth date is incorrect. Please try again! "<Br/> return <br/> end if <br/> else <br/> If DD> 29 or DD <1 then <br/> label_false.text =" Birth date Error, please try again! "<Br/> return <br/> end if <br/> end select <br/> 'after verification, the data is converted to a normal date type dateout <br/> dim yymmdd as string = YY & "-" & mm & "-" & DD <br/> dim dateout as date = datetime. parse (yymmdd)

 

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.