Solution error "dropdownlist1" has an invalid selectedindex because it is not in the project list.

Source: Internet
Author: User

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.

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: 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.