C# 迭代 CheckBoxList 将所选项目插入 SQL 列
我有一个 CheckBoxList,显示大约 20 个选项。我想迭代并从列表中取出所选项目并将它们插入到数据库中的 5 个不同列中。
我在选择 5 个项目后禁用复选框列表,所以我在那里很好。我只需要知道如何迭代并插入所选项目。
我怎样才能完成这个任务呢?提前致谢!
I have a CheckBoxList that displays around 20 options. I would like to iterate through and take the selected items from the list and insert them into 5 different columns in a database.
I disable the checkboxlist after 5 items are selected so I am good there. I just need to know how to iterate through and insert the selected items.
How would I get this accomplished? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以获得像这样选中的复选框,
如果它不是最外层的容器(例如表单),请将
this
替换为具有复选框的容器。然后您可以循环检查checkBoxes 中的项目并制定插入语句。
you can get the checked checkboxes like this
replace
this
with a container that has the checkboxes if it's not the outer most container such as a Form.and then you can loop thru items in checkedCheckBoxes and formulate your insert statement.
您是否有复选框列表或
CheckedListBox
控件?由于已经为第一个问题提供了答案,请查看
CheckedIndices
或CheckedItems
属性CheckedListBox
控件(如果您使用的是该控件)。快速示例:
Do you have list of checkboxes or
CheckedListBox
control?As answers have been provided for first one already, take a look at
CheckedIndices
orCheckedItems
properties ofCheckedListBox
control in case that's what you use.Quick example:
试试这个:
Try this: