CheckBoxList 只能选2个选项


//

////下面判断用户是否多选,每选择一次比较一次,看是否超过规定名额
//string ClickedItem = Request.Form["__EVENTTARGET"];//得到用户点击的是哪个
//ClickedItem = ClickedItem.Split(':')[1];//进行拆分处理
//int index = Int32.Parse(ClickedItem);


int x, y;
y = 0;
int n = 2;


for (x = 0; x < this.chkgzys.Items.Count; x++)
{
if (this.chkgzys.Items[x].Selected)
{
y = y + 1;//通过循环得到用户的选项数量
if (y > n)//跟规定名额做比较
{

ShowErrMsg("只能任选两项");
this.chkgzys.Items[x].Selected = false;//让用户超过的选项取消


return;

}

}
}

//

原文地址:https://www.cnblogs.com/lyl6796910/p/3700204.html