将CheckBox列表项插入数据库时​​出现问题 [英] Problem inserting CheckBox List Item to Database

查看:121
本文介绍了将CheckBox列表项插入数据库时​​出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复选框列表,我想将其Checked项目插入数据库;

我使用了这段代码:

  for  int  i =  0 ; i <  checkBox_service.Items.Count; i ++)
{

if (checkBox_service.Items [i] .Selected == true
{
strcheck + = + checkBox_service.Items [i] .ToString()+ ;
}
}



在数据库中显示

 System.Web.UI.WebControls.CheckBoxList  
。根据输入的所有其他字段都有正确的数据...

我找不到任何错误,请指导我...

解决方案

< blockquote>尝试使用CheckBoxListItem的 Text Value 属性(适用于你)。像这样:



 checkBox_service.Items [i] .Text 
checkBox_service.Items [i] .Value


尝试使用 checkBox_service.Items [i] .Text


I have a check box list, and I want to insert its Checked items to Database;
I used this code:

for (int i = 0; i < checkBox_service.Items.Count; i++)
        {
            
            if (checkBox_service.Items[i].Selected == true)
            {
                strcheck += "" + checkBox_service.Items[i].ToString() + ",";
            }
        }


In Database it is displaying

System.Web.UI.WebControls.CheckBoxList


in CheckBox field instead of Selected item. All other fields are having correct data as per entered...
I couldn't find any error, please guide me...

解决方案

Try using either the Text or Value property of CheckBoxListItem (whatever suits you). Like this:

checkBox_service.Items[i].Text 
checkBox_service.Items[i].Value


try with checkBox_service.Items[i].Text


这篇关于将CheckBox列表项插入数据库时​​出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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