When making a message board, select the page to use the dropdownlist Server Control.CodeThe file assigned a value to him. The page 1 test throws an exception. Why?
Exception: system. argumentoutofrangeexception: "dropdownlist1" has an invalid selectedvalue because it is not in the project list.
I don't know if you have encountered such a problem. I found some information on the Internet, finally found a solution, wrote down the solution, and gave a solution to the person who encountered the same problem as me.
The method is as follows:
This attribute returns the Value Attribute of the selected listitem. The selectedvalue attribute is usually used to determine the value of the selected item in the list control. If multiple items are selected, the minimum value of the selected item is returned. If no item is selected, an empty string ("") is returned (""). The selectedvalue attribute can also be used to select an item in the list control by setting this attribute with the value of this item. If no item in the list control contains a specified value, system. argumentoutofrangeexception is thrown.
You only need to assign values like this:
This. lblpagecur. Text = "1 ";
This. dropdownlist1.selectedindex = dropdownlist1.items. indexof (dropdownlist1.items. findbyvalue (this. lblpagecur. Text ));
If the specified item is not found through findbyvalue, It is null, and items. indexof (null) will return-1.