CheckBoxList的值相加

代码如下:

string str = "0";
            int allvalue = 0;
            CheckBoxList CBL = this.FindControl("CheckBoxList1"as CheckBoxList;

            if (CBL != null)
            {
                for (int i = 0; i < CBL.Items.Count; i++)
                {


                    if (CBL.Items[i].Selected)
                    {
                        str = CBL.Items[i].Value;
                        int a = Convert.ToInt32(str);
                        allvalue = allvalue + a;
                        //str = str + CBL.Items[i].Value;
                    }
                }
            }
            Response.Write(allvalue.ToString());

此代码无需解释吧。此代码要求CheckBoxList的值是数字,因为要相加么。

posted @ 2011-11-06 16:08  草珊瑚  阅读(393)  评论(0)    收藏  举报