Csharp:asp.netCheckBoxListdatabind

我们提供的服务有:成都网站设计、网站制作、微信公众号开发、网站优化、网站认证、集美ssl等。为上千企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的集美网站制作公司


        

/// 
        /// CheckBoxList數據源
        /// 塗聚文
        /// 20130705
        ///
        /// 
        private void setCheckBoxList()
        {
           DataTable dt = new DataTable();
           CheckBoxList1.Items.Clear();
          dt = geovindu_branchBLL.SelectGeovindu_branchNameDt();
          CheckBoxList1.DataSource = dt;
          this.CheckBoxList1.DataTextField = "B_Name";
          this.CheckBoxList1.DataValueField = "B_EnglishName";
          CheckBoxList1.DataBind();
        }
        /// 
        ///
        /// 
        /// 
        /// 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                setCheckBoxList();
            }
        
        }
        /// 
        /// 獲取選擇的項目
        /// 
        /// 
        /// 
        protected void Button1_Click(object sender, EventArgs e)
        {
            string variable = string.Empty;
            int i = 0;
            foreach (System.Web.UI.WebControls.ListItem oItem in CheckBoxList1.Items)
            {
                if (oItem.Selected) // if you want only selected
                {
                    if (i ==0)
                    {
                       variable = oItem.Value;
                    }
                    else
                    {
                        variable = variable + "," + oItem.Value;
                    }
                    i++;
                }
                // otherwise get for all items
                //variable = oItem.Value;
                  
            }
            //傳值給父頁面
            this.Page.Controls.Add(new LiteralControl(string.Format("", variable)));
       
             //關閉此視窗
            this.Page.Controls.Add(new LiteralControl(""));

当前题目:Csharp:asp.netCheckBoxListdatabind
文章转载:http://scjbc.cn/article/pcdice.html

其他资讯