Cannot have multiple items selected in a dropdownlist

Source: Internet
Author: User

For a long period of time, it was paid for the company's info syteline ERP maintenance.

I finally have time to go to development today.Program. For a long time, development has always been based on the common habits of writing programs. This thinking will use another method for development. In this way, there will be new problems.
The problem is: Assign the selected value to the drop-down menu (dropdownlist) and bind it as follows:

This . Dropdownlistpinzhong. Items. findbyvalue (objdatarow [ " Pinzhongid " ]. Tostring (). Selected = True ;

 

At runtime,

It displays an error SYS. webforms. pagerequestmanagerservererrorexception: cannot have multiple items selected in a dropdownlist .:

 

Inspired by the prompt, "cannot have multiple items selected in a dropdownlist" can be used to clear the selected item by using clearselection () in the dropdownlist method before data binding. SetCodeChanged:

This . Dropdownlistpinzhong. clearselection ();
This . Dropdownlistpinzhong. Items. findbyvalue (objdatarow [ " Pinzhongid " ]. Tostring (). Selected = True ;

 

Run again and the error disappears:

 

Later, I found that some netizens encountered the same problem on the Internet and found another solution, as shown in the code below:

This . Dropdownlistpinzhong. selectedindex = This . Dropdownlistpinzhong. Items. indexof ( This . Dropdownlistpinzhong. Items. findbyvalue (objdatarow [ " Pinzhongid " ]. Tostring ()));

 

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.