gpt4 book ai didi

C# CheckBoxList 选中的项目到字符串

转载 作者:太空宇宙 更新时间:2023-11-03 17:50:51 24 4
gpt4 key购买 nike

我有一个包含一些项目的 CheckBoxList,当用户单击一个按钮时,我希望将选中的文本框的值添加到一个字符串中。我在这里到处寻找答案,但大多数都不起作用或产生不良结果。这是我到目前为止的代码:

string selectedItems = CheckBoxList1.Items.???

不知道从这里去哪里。感谢您的帮助!

最佳答案

您可以将 String.Join 与 LINQ 一起使用,例如:

string selectedItems = String.Join(",",
CheckBoxList1.Items.OfType<ListItem>().Where(r => r.Selected)
.Select(r => r.Text));

这将为您提供所有选定项目的逗号分隔字符串。

关于C# CheckBoxList 选中的项目到字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26785840/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com