public void BindCheckBoxList(CheckBoxList cbl, bool isText, string values)
{
values = string.IsNullOrEmpty(values) ? ("") : (values);
if (values.Length > 0)
{
if (isText)
{
string[] tempValues = values.Split(',');
for (int i = 0; i < tempValues.Length; i++)
{
for (int j = 0; j < cbl.Items.Count; j++) {
if (cbl.Items[j].Text.Trim() == tempValues[i].ToString())
{
cbl.Items[j].Selected = true;
}
}
}
}
else {
string[] tempValues = values.Split(',');
for (int i = 0; i < tempValues.Length; i++)
{
for (int j = 0; j < cbl.Items.Count; j++)
{
if (cbl.Items[j].Value.Trim() == tempValues[i].ToString())
{
cbl.Items[j].Selected = true;
}
}
}
}
}
else {
}
}
本文介绍了一个方法,用于根据提供的字符串值来设置ASP.NET中CheckBoxList控件的选中状态。该方法支持通过文本或值进行匹配。

2231

被折叠的 条评论
为什么被折叠?



