从复选框中选择多个值 [英] seleceting multiple values from checkbox

查看:108
本文介绍了从复选框中选择多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨......
是否可以在数据库的同一列中存储2个或更多选定的复选框值.我正在使用asp.net 3.5和sql 2005.
实际上,我想说的是,如果选择一个复选框,那么它会存储在数据库的一列中;但是如果我一次选择多个复选框,那么它的值也应该存储在同一列中....
请帮帮我........
谢谢

hi....
is this possible to store 2 or more selected check-box values in same column in data base.i am using asp.net 3.5 and sql 2005..

Actually i want to say that if select one check-box then it stored in one column in database but if i select multiple check-box at one time then also its value should stored in same column....
please help me out........
thanks

推荐答案

您正在做的事情不太正确.
理想情况下,您应该将列表的所有值存储在表中.

根据用户的选择,我们应该将一个键和所有选择的值保存为表中的单独行,该表用于跟踪用户选择的内容.

以串联格式保存项目违反了首个普通格式.
What you are doing is not quite correct.
You should ideally be storing all the values of the list in a table.

Based on what the user chooses, we should save a key and all the values selected as separate rows in a table used for tracking what the user has selected.

Saving items in a concatenated format violates first normal form.


CheckBoxList
是的,您可以使用定界符并附加所有选定的值,然后插入到单个数据库列中.从数据库检索时使用定界符进行拆分.

[更新]
CheckBoxList
Yes you can use a delimiter and append all the selected values and insert into single database column. Split using the delimiter while retrieving from database.

[update]
StringBuilder sb = new StringBuilder();
           foreach (ListItem item in CheckBoxList1.Items)
           {
               if (item.Selected == true)
               {

                   sb.Append(item.Text + "|");
               }
           }
           //Response.Write(sb.ToString());
           //insert the sb value into the database


[/update]


[/update]


这篇关于从复选框中选择多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆