怎么判断CheckBoxList中选中项是相邻的 如果不是相邻项 保存的时候会给提示
如题 --------------------编程问答-------------------- 调用
bool flag = Check(this.CheckBoxList1);
--------------------编程问答-------------------- int old=-1;
private bool Check(CheckBoxList cbl)
{
bool flag = true;
List<int> list_index = new List<int>();
ListItemCollection lic = cbl.Items;
for (int i = 0; i < lic.Count;i++ )
{
if (lic[i].Selected)
{
list_index.Add(i);
}
}
if (list_index != null && list_index.Count > 1)
{
for (int i = 1; i < list_index.Count; i++)
{
int temp = list_index[i - 1] + 1;
if (list_index[i] != temp)
{
flag = false;
break;
}
}
}
else
flag = false;
return flag;
}
for(int i=0;i<checkboxList.Items.Count;i++)
{
if(checkboxList.Items[i].Selected)
{
if(old==-1){old=i;contiue;}
if(old==i-1){"相邻"}
old=i;
}
} --------------------编程问答-------------------- 忘了说了 是用js前台验证 --------------------编程问答-------------------- 用个for循环遍历CheckBoxList中的项,
if (chek[i].Checked==true && chek[i+1]Checked==false)
alert(xxxx);
else
.....
补充:.NET技术 , ASP.NET