多項選擇控件

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

namespace 選擇控件實例
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string strNum1, strNum2="";
            string strLable;
            strNum1 = RadioButtonList1.SelectedItem.ToString();  //取RadioButtonList1控件目前選中的值
            foreach (ListItem item in CheckBoxList1.Items) //將CheckBoxList1控件中的值遍歷顯示在item中
            {
                if (item.Selected == true) //判斷item中的值哪些是被選中的
                {
                    strNum2 = strNum2 + item.Text;
                }
            }
            strLable = "你最想去的國家" + strNum1 + ",你喜歡的運動" + strNum2;
            Label3.Text = strLable.ToString();
        }
    }
}

發佈了32 篇原創文章 · 獲贊 1 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章