首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

数据库查询出来字符串怎么绑定到CheckBoxList

2013-07-01 
数据库查询出来字符串如何绑定到CheckBoxList数据库保存的字符串为124CheckBoxList Item有1 2 3 4 5 6

数据库查询出来字符串如何绑定到CheckBoxList
数据库保存的字符串为
;1;2;4;

CheckBoxList Item有1 2 3 4 5 6

如何根据数据库的字符串把相应的 1 2 4默认打勾?
[解决办法]
http://www.cnblogs.com/shawker/archive/2009/03/17/1414795.html
[解决办法]

 string result = ";1;2;4;";
            var list=result.Split(';');
            foreach (ListItem item in this.CheckBoxList1.Items)
            {
                if (list.Contains(item.Value))
                    item.Selected = true;
            }

[解决办法]

string str = ";1;2;4;";
            string[] arr = str.Substring(1, str.Length - 2).Split(';');
            foreach (string obj in arr)
            {
                for (int i = 0; i < CheckBoxList1.Items.Count; i++)
                {
                    if (obj == CheckBoxList1.Items[i].Value)
                    {
                        this.CheckBoxList1.Items[i].Selected = true;
                    }


                }
            }

热点排行