日期:2014-05-18  浏览次数:20399 次

[20 分] 请问这个该怎么写?
foreach(ListItem   l   in   CheckBoxList1.Items)
{
        l.Selected   =   true;
}

我断点后发现,上面这个循环不执行   ListItem   l   这句,到   in   的时候就结束了。请问怎么才能正确循环   CheckBoxList1   内的每一个   Item   呢?

------解决方案--------------------
你的方法是对的,

也许你的 CheckBoxList1.Items.Count == 0
------解决方案--------------------
foreach语句中的ListItem l 是只读的,不能改变他的值
用for吧
------解决方案--------------------
string str = " ";
foreach (ListItem li in cblrighgs.Items)
{
if (li.Selected == true)
{
str += li.Value+ "; ";
}
}

Response.Write(str);
------解决方案--------------------
循环的代码没有错,但估计是地方错了

确定循环的时候CheckBoxList1已完成绑定或已根据ViewState初始化