你判断GoodboyCheckBoxList.Items中Selected属性为TRUE的个数就行了,超过5就提示他复选不能超过五项

解决方案 »

  1.   

    取出后是用,分隔的字符串。再分开看看循环几次就知道了
    string delimStr = ",";
    char [] delimiter = delimStr.ToCharArray();

    string [] split = null; split = sLibClassId.Split(delimiter); ing i;
    foreach (string classid in split) 
    {
    i++;
    }
                                 //最后i就是如果>5那么。。
      

  2.   

    上面说的都对,还有要记住要实现上面的代码必须将checkboxlist的autopostback属性设置为真。不过上面的方法会导致闪屏。不如使用服务端html控件。
      

  3.   

    private void btSend_Click(object sender, System.EventArgs e)
    {
    db.Sql="update [user] set YesType=0";
    db.ExecuteNonQuery();//
    if(this.chechNum())
    {
    message.Text="提交失败!";
    return;
    }
    // for (int i = 0 ; i<GoodboyCheckBoxList.Items.Count;i++ )
    {
    if( GoodboyCheckBoxList.Items[i].Selected )
    {
    UpdateData(GoodboyCheckBoxList.Items[i].Value.ToString());
    }

    }
               message.Text="提交成功!";
    }
    private void UpdateData(string strid)
    {
    db.Sql="update [user] set YesType=1 where userid="+Convert.ToInt32(strid)+"";
    db.ExecuteNonQuery();
    }
    //
    private bool checkNum()
    {
    int iCount=0;
    for(int i=0;i<GoodboyCheckBoxList.Items.Coutn;i++)
    {
    if(GoodboyCheckBoxList.Items[i].Selected)
    iCount++;
    }if(iCount>5)
    return true;
    else
    return false
    }
    //