数据库查询出来字符串怎么绑定到CheckBoxList
数据库查询出来字符串如何绑定到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
------解决方案--------------------
------解决方案--------------------
数据库保存的字符串为
;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;
}