简体   繁体   English

从db检索值并在c#中的复选框列表中检查它们

[英]retrieve values from db and check them in checkboxlist in c#

I already inserted the values from a checkboxlist as a string separated into the database but for some reason i'm not able to recheck these values when i select them from the database. 我已经将复选框列表中的值作为字符串插入数据库中,但是由于某些原因,当我从数据库中选择它们时,我无法重新检查这些值。 can someone please help me with that? 有人可以帮我吗?

            string category = dt.Rows[0][14].ToString();
            string[] strCat = category.Split(',');

            for (int i = 0; i < strCat.Length; i++)
            {
                for (int j = 0; j < checkCat.Items.Count; j++)
                {
                    if (checkCat.Items[j].Text == strCat[i])
                    {
                        checkCat.Items[j].Selected=true;
                    }
                }
            }

put them in a panel 将它们放在面板中

        string category = dt.Rows[0][14].ToString();
        string[] strCat = category.Split(',');

        for (int i = 0; i < strCat.Length; i++)
        {

            foreach (CheckBox box in panel.Controls.OfType<CheckBox>())
            {
                if(box.Text == strCat[i])
                {
                  box.Checked = true; 
                }
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM