SQL中的复选框列表未选择第一项

问题描述

我有一个带有复选框列表的表单。我希望以后可以更新此表格。因此,我将数据存储在sql中,然后稍后将其检索以填充保存时的表格。但是由于某种原因,复选框列表会选择先前选择的所有选项,但第一个除外。

这是我的代码

CheckBoxList8.Items.Clear();
CheckBoxList8.AppendDataBoundItems = true;
DateTime pickupDate = DateTime.Parse(SessionDateCalendar.Text);

sqlConnection con7 = new sqlConnection(strcon);
if (con7.State == ConnectionState.Closed)
{
    con7.open();
}

// this sql command finds all the possible options for the checkBox list,as they are different depending on the customer. 

sqlCommand cmd7 = new sqlCommand("SELECT * from customer_outcomes WHERE NYEIS_ID='" + DropDownList1.SelectedValue + "' and @SessionDate >= start_date And  @SessionDate <= end_date;",con7);

cmd7.Parameters.AddWithValue("@SessionDate",pickupDate);
cmd7.CommandType = CommandType.Text;

sqlDataAdapter da7 = new sqlDataAdapter(cmd7);
DataTable dt7 = new DataTable();
da7.Fill(dt7);
if (dt7.Rows.Count >= 1)
{
    // this splits all the possible options,as they are prevIoUsly stored with ";" as a separator and then fills the check Box list. (this is done successfully. When debugging,all the data seems to be stored correctly. I will attach the debugging info below. 
    string[] outcomesObject = dt7.Rows[0]["outcomes"].ToString().Trim().Split(';');
    for (int i = 0; i < outcomesObject.Length; i++)
    {
        CheckBoxList8.Items.Add(outcomesObject[i]);
    }

    // this takes the data from a prevIoUs sql cmd and splits the data from the saved sql table,it is split and then stored as a string called Outcomessplitter. 
    string OutcomesSelector = dt.Rows[0]["outcomes"].ToString().Trim();
string[] Outcomessplitter = OutcomesSelector.Split(new[] { ";" },StringSplitOptions.None);

    //this selects all the options that were prevIoUsly selected. 
    foreach (ListItem li in CheckBoxList8.Items)
        li.Selected = Outcomessplitter.Contains(li.Text);

    CheckBoxList8.DataBind();

这是我认为相关的调试信息。

dt.Rows[0]["outcomes"].ToString().Trim();

[33] =“ \ r \ n-自己脱掉简单的衣服,如袜子/鞋子\ t; \ r \ n-换尿布\ t; \ r \n3。David会指出/使用近似词表达他的需要/需求; \ r \ n-产生与真实单词近似的行话\ t; \ r \ n-使用近似的单词...

OutcomesSelector =

“-自行脱下简单的衣服,例如袜子/鞋子\ r \ n-更换尿布\ t; \ r \n3。David会指出/使用近似的词语来表达自己的需求/需求; \ r \ n-产生与真实单词近似的行话\ t; \ r \ n-使用单词近似以...

Outcomessplitter.Contains(li.Text);

[0] =“-自行脱掉袜子/鞋子等简单的衣服\ t [1] =“ \ r \ n-可更换尿布\ t” [2] =“ \ r \ n3。戴维会指出/使用近似词来表达自己的需求/需求”

我唯一能说的是,当代码从> dt移到> OutcomesSelector时,\ r \ n被删除。当我在调试期间手动将其放入时,则选择了第一项。请帮忙。我不知道如何选择第一个项目以及> dt.rows

中列出的其他项目

感谢您的帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...