DROPDOWNLIST Binding Database

xiaoxiao2021-04-11  1.2K+

DropDownload = MyReader; // myReader for the result set of ExecuteReader ()

DropDownList1.DataTextField (DataValuefield) = "Which column name is written in the data set in MyReader, which one is written to write."

DropDownList1.DATABIND ();

There are three DROPDOWNLIST controls on the ASPX page, the background database built table, the annual month.

DropDownList1 means that DropDownList2 means the month, DropDownList3 means the day;

Note Use the AutoPostBack properties of these three DropDownList controls to True.

Users can easily choose the Year and Moon, and the monthly date will change according to the month, monthly

The code code of its inautions is as follows:

Private Void Page_Load (Object Sender, System.EventArgs E)

{

DateTime TNOW = DATETIME.NOW; // Today

Arraylist alyear = new arraylist ();

INT I;

For (i = 2002; i <= 2010; i )

Alyear.Add (i);

Arraylist almonth = new arraylist ();

For (i = 1; i <= 12; i )

Almonth.Add (i);

IF (! this.ispostback)

{

DropDownList1.datasource = alyear;

DropDownList1.DATABIND (); // Binding Year

// Select the current year

DropdownList1.SelectedValue = T1ow.Year.toString ();

DROPDOWNLIST2.DATASOURCE = Almonth;

DROPDOWNLIST2.DATABIND (); // Binding month

// Select the current month

DropDownList2.selectedValue = t1ow.month.tostring ();

Int year, month;

Year = int32.parse (DropDownList1.selected);

Month = int32.parse (DropdownList2.SelectedValue);

Binddays (Year, Month); // Binding Day

// Select the current date

DropDownList3.SelectedValue = t1ow.day.tostring ();

}

}

// Judgment leap year

Private bool checkleap (int year)

{

IF ((Year% 4 == 0) && (Year% 100! = 0) || (Year% 400 == 0)))

Return True;

Else Return False;

}

// Bind the monthly days

Private void binddays (int year, int month)

{INT I;

ArrayList alday = new arraylist ();

Switch (Month)

{

Case 1:

Case 3:

Case 5:

Case 7:

Case 8:

Case 10:

Case 12:

For (i = 1; i <= 31; i )

Alday.Add (i);

Break;

Case 2:

Checkleap (Year))

{for (i = 1; i <= 29; i ) alDay.add (i);

Else

{for (i = 1; i <= 28; i )

Alday.Add (i);

Break;

Case 4:

Case 6:

Case 9:

Case 11:

For (i = 1; i <= 30; i )

Alday.Add (i);

Break;

}

DROPDOWNLIST3.DATASOSOSOURCE = ALDAY;

DropDownList3.DATABIND ();

}

// Choose the year

Private void DropdownList1_selectedIndexchanged (Object Sender, System.Eventargs E)

{

Int year, month;

Year = int32.parse (DropDownList1.selected);

Month = int32.parse (DropdownList2.SelectedValue);

Binddays (Year, Month);

}

// Select month

Private void DropdownList2_selected IndexChanged (Object Sender, System.Eventargs E)

{

Int year, month;

Year = int32.parse (DropDownList1.selected);

Month = int32.parse (DropdownList2.SelectedValue);

Binddays (Year, Month);

}

转载请注明原文地址: https://www.9cbs.com/read-133593.html

New Post(0)