CheckBoxList从数据库中取值的问题
string strTerm = dr[ "term "].ToString();
string[] strTerms = strTerm.Split( ', ');
foreach (ListItem lItem in cblTerm.Items)
{
for (int i = 0; i < strTerms.Length; i++)
{
if (lItem.Value == strTerms[i])
{
lItem.Selected = true;
}
}
}
把取出来的值让CheckBoxList自动打上勾 我那样怎么不行呢?
[解决办法]
string strTerm = dr[ "term "].ToString();
string[] strTerms = strTerm.Split( ', ');
for (int i = 0; i < strTerms.Length; i++)
{
cblTerm.Items.FindByValue(strTerms[i])Selected = true;
}
这就够了,foreach不用