saving checkbox values in vb.net

亡梦爱人 提交于 2019-12-25 03:18:20

问题


i have 50 checkboxes for 50 american states. The user can choose all 50 or only 1( so basically any number he wants). Based on his choice, I want to insert or update the table in sql server 2008. e.g-

Color = blue and chk1=check, chk2= check and chk3 = check (chk = checkbox). now the user wants to ad 10 more states to this or remove these 3 and add 5 more. so u basically get the idea. the table in database looks like this - ID Color State_id there is a table called states, so stateid shall come from there. so how do i do a loop insert or update in vb.net?


回答1:


This might not be answering your question directly... but you may want to consider using a checked listbox of 50 entries rather than 50 discreet checkboxes. At least this way you will be able to loop through the CheckedItems collection updating whatever it is you want to do.




回答2:


You can use an array of checkboxes and process them through a loop. There are a couple of ways to do this. One, assign each element in an array of checkboxes to one of the 50 you put on the form in design mode. Two, you can create a new checkbox for each array element at runtime as position it on the form. With the second method, you don't need to add the checkboxes in design mode.



来源:https://stackoverflow.com/questions/2158693/saving-checkbox-values-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!