[英]Vb.net create checkbox items from comma delimited string
I have a simple ASP checkbox list (see bellow): 我有一个简单的ASP复选框列表(请参见下面的内容):
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
</asp:CheckBoxList>
I have a string in my vb.net (see bellow): 我的vb.net中有一个字符串(请参见下面的内容):
"1,2,3,4,5,6,7,8,9,10"
“ 1,2,3,4,5,6,7,8,9,10”
I want to be able to loop through each number in my string and add each one as a checkbox in my checkbox list. 我希望能够遍历字符串中的每个数字,并将每个数字作为复选框添加到我的复选框列表中。 I have searched online though most solutions I have come across seem slightly different from what I want to achieve.
我在网上搜索过,尽管遇到的大多数解决方案似乎与我想要实现的解决方案略有不同。
This is the code I have so far: 这是我到目前为止的代码:
For Each s In checkBoxString.split(",")
Next
I was wondering if anyone could give me any suggestions to how I can achieve this. 我想知道是否有人可以给我一些有关如何实现这一目标的建议。 Any help is appreciated, Thank you in advance.
感谢您的帮助,在此先感谢您。
You need to create a ListItem and add it to the list of CheckBoxList items: 您需要创建一个ListItem并将其添加到CheckBoxList项目列表:
For Each s In checkBoxString.split(",")
CheckBoxList1.Items.Add(New ListItem(s))
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.