现在的位置: 首页 > 综合 > 正文

CheckBoxList 获取选择的内容和根据内容判断是否选择

2012年09月18日 ⁄ 综合 ⁄ 共 788字 ⁄ 字号 评论关闭

//获得选择的Value值         

string topupway = string.Empty;
            for (int i = 0; i < cblTopUpWay.Items.Count; i++)
            {
                if (cblTopUpWay.Items[i].Selected)
                {
                    topupway += cblTopUpWay.Items[i].Value+"|";//这里也可以用逗号(,)
                }
            }
            Response.Write(string.Format("<script>alert('{0}')</script>",topupway));

//根据值选择的进行判断是否选择

                string way = "net|168|mobile|mobilecard|card|other|";
                string checkvalue = string.Empty;
                string[] topupway =way.Split('|');
                for (int i = 0; i < cblTopUpWay.Items.Count; i++)
                {
                    checkvalue = cblTopUpWay.Items[i].Value;
                    if (Array.IndexOf<string>(topupway, checkvalue) != -1)
                    {
                        cblTopUpWay.Items[i].Selected = true;
                    }
                    else
                    {
                        cblTopUpWay.Items[i].Selected = false;
                    }
                }

抱歉!评论已关闭.