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 ()));