问题描述
publicpartialclassdiaocha:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){SetBind();}}protectedvoidSetBind(){string[]DataSorce1=newstring[]{"男20-25岁","男26-35","男36-45","男46以上","女20-25岁","女26-35","女36-45","女46以上"};CheckBoxList1.DataSource=DataSorce1;CheckBoxList1.DataBind();}protectedvoidButton1_Click(objectsender,EventArgse){stringCheckBoxList1Item=CheckBoxList1.SelectedItem.Text;Response.Write(CheckBoxList1Item);}}在我按了BUTTON后CheckBoxList1.SelectedItem.Text怎么会获得我选的值的???
解决方案
解决方案二:
stringCheckBoxList1Item="";for(inti=0;i<CheckBoxList1.Items.Count;i++){if(CheckBoxList1.Items[i].Selected){CheckBoxList1Item+=CheckBoxList1.Items[i].Text;Response.Write(CheckBoxList1Item);}}
解决方案三:
Tozhanghy1028我的意思不是如何获取CheckBoxList所选的值.而是服务器在处理回发事件的时候.服务器是如何知道我所选的项.?不知道我有没讲清楚.我表达能力比较差.不好意思.