问题描述
我正在使用GridView,我在其中有一个CheckBox作为模板字段我想将复选复选框的值设为1,而未将其复选为0,因此我想将所有选中的一个存储在DB表中的一列中在另一栏中取消选中我怎么做
这里是我的代码:
I am Using GridView and I have a CheckBox in it as Template Field I want to give the checked checkbox's value as 1 and the one's not checked as 0 so I want to store all checked one's in one column in DB Table and all unchecked one's in another column how do I do it
here is my code:
string chk;
for (int i = 0; ChkBoxMarkPr.Items.Count; i++)
{
if (ChkBoxMarkPr.Items[i].Selected == true)
{
insert into tablename (columnname) values (i); // or what do I type in here in the insert query.
}
}
ChkBoxMarkPr是为.cs文件中的checkBox创建的实例这是正确的吗?
ChkBoxMarkPr is a instance created for the checkBox in .cs file is this correct?
推荐答案
string chk;
SqlCommand cmd = null;
for (int i = 0; ChkBoxMarkPr.Items.Count; i++)
{
cmd = new SqlCommand("INSERT INTO [TABLE_NAME] (COLUMN_NAME) VALUES ("+ ChkBoxMarkPr.Items[i].Selected + ")", yourSqlConnectionObject);
cmd.ExecuteNonQuery();
}
是的,同意Tadit所说的(解决方案#1)。你也可以这样走。然后你必须允许列的 null
值。 :)
-KR
And yeah, agree with what Tadit said (Solution #1) as well. You can go that way too. Then you have to allow the null
values for column. :)
-KR
这篇关于将选中的复选框存储到DB中的一列中,将未选中的复选框存储在另一列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!