checkboxlist 多选项获值

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace CSCDF.Web
{
    public partial class test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) 
            {
                BindchkCountry();
            }
            
        }
        protected void BindchkCountry()
        {
            CSCDF.BLL.Country countrybll = new CSCDF.BLL.Country();
            DataSet ds = new DataSet();
            ds = countrybll.GetList("");
            chkCountry.DataTextField = "CountryName";
            chkCountry.DataValueField = "CountryID";
            chkCountry.DataSource = ds;
            chkCountry.DataBind();
        }

        protected void btnTest_Click(object sender, EventArgs e)
        {
            string s="";
            for (int i = 0; i < chkCountry.Items.Count; i++)
            {
                if (chkCountry.Items[i].Selected) 
                {
                    s += chkCountry.Items[i].Value.Trim()+"|";
                }   
            } 

            Maticsoft.Common.MessageBox.Show(this,s);
        }
    }
}
用心写代码,不辜负程序员之名。
原文地址:https://www.cnblogs.com/thinkingthigh/p/3044673.html