DropDownList SelectedIndex problem
Varför kan jag inte sätta år som valt på detta sätt?
DateTime myDate = DateTime.Now;
dd_year.SelectedIndex = myDate.Year;
Jag får nedanstående meddelande.
Specified argument was out of the range of valid values. Parameter name: value
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: value
Source Error:
Line 132: {
Line 133: lbl_test.Text = myDate.Year.ToString(); //+ " " + myDate.Month + " " + myDate.Day;
Line 134: dd_year.SelectedIndex = myDate.Year;
Line 135: dd_month.SelectedIndex = myDate.Month;
Line 136: dd_day.Items.Clear();
Svara
Sv: DropDownList SelectedIndex problem
Ok, det är fredag och jag är trött.
dd_year.SelectedIndex är ju inte samma som året.
Indexet för 2004 är ju 1.
index 0 <--Year-->
index 1 2004
index 2 2005
index 3 2006
index 4 2007
.
.
.
Svara