简体   繁体   中英

Set selected values in asp ListBox with one line

I'm trying to set the selected values in an asp ListBox webcontrol from a string[] but I'm getting the error

Only assignment, call, decrement, increment and new object expressions can be used as a statement Here's what I have so far...

string[] pageRoles = new string[] {"Admin", "Users", "Publisher"};
pageRoles.ToList().ForEach(r => rolesListBox.Items.FindByValue(r).Selected == true);

I believe the problem is you were using a comparison operator instead of assignment.

string[] pageRoles = new string[] {"Admin", "Users", "Publisher"};
pageRoles.ToList().ForEach(r => rolesListBox.Items.FindByValue(r).Selected = true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM