如何在一列中的数据库中插入复选框值 [英] How to insert checkboxes values in database in one column
问题描述
朋友们,
正在使用c#和Sqlserver 2005处理asp.net项目。
我想在数据库字段中插入复选框值。
我的网页上有5个复选框。
复选框1
复选框2
复选框3
复选框4
复选框5
如果选中checkbox1,则表格列中的值应为1
如果选中checkbox2,则表格列中的值应为1
如果复选框3选中了值表格列应为1
如果未选中checkbox4,则表格列中的值应为0
如果未选中checkbox5,则表格列中的值应为0
在列中它应该保存为11100
请你帮我。
谢谢。
Hi friends,
am working on asp.net project using c# and Sqlserver 2005.
I want to Insert checkboxes values into database field.
I have 5 checkboxes on my webpage.
Checkbox1
Checkbox2
Checkbox3
Checkbox4
Checkbox5
If checkbox1 is selected the value in table column should be 1
If checkbox2 is selected the value in table column should be 1
If checkbox3 selected the value in table column should be 1
If checkbox4 is NOT selected the value in table column should be 0
If checkbox5 is NOT selected the value in table column should be 0
In column it should save as 11100
Please can u help me.
Thanks.
推荐答案
for windows Application
for windows Application
string chkVal = checkBox1.CheckState.GetHashCode().ToString()+
checkBox2.CheckState.GetHashCode().ToString()+
checkBox3.CheckState.GetHashCode().ToString()+
checkBox4.CheckState.GetHashCode().ToString()+
checkBox5.CheckState.GetHashCode().ToString();
for web Application
for web Application
string chkVal = (CheckBox1.Checked ? "1" : "0").ToString() +
(CheckBox2.Checked ? "1" : "0").ToString() +
(CheckBox3.Checked ? "1" : "0").ToString() +
(CheckBox4.Checked ? "1" : "0").ToString() +
(CheckBox5.Checked ? "1" : "0").ToString();
Label1.Text = chkVal;
:):):)
:):):)
拿一个StringBuilder
。
在检查CheckBox
检查状态后,将1或0添加到它。
Take aStringBuilder
.
Append 1 or 0 to it after checking theCheckBox
Checked status.
StringBuilder sb = new StringBuilder();
if(checkbox1.Checked)
sb.Append("1");
if(checkbox2.Checked)
sb.Append("1");
........
然后最后只保存 sb.ToString()
到数据库。
这篇关于如何在一列中的数据库中插入复选框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!