标签:
CheckBoxList控件获取多选择,需要遍历,环境:vs2008
在页面上添加CheckBoxList控件,输入项值 a,b,c,d.然后添加按钮 Button2确定,如何获取CheckBoxList控件多选择呢?
protected void Button2_Click(object sender, EventArgs e)
{
string ChbSelected = "";
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected == true)
ChbSelected += CheckBoxList1.Items[i].Value + ",";
}
if (ChbSelected != "")
ChbSelected = ChbSelected.Substring(0, ChbSelected.Length - 1);
else
ChbSelected = "空白";
Response.Write("your choice is "+ChbSelected );
}
测试通过.
按照同样道理,CheckBoxList在客户端用js操作,假如经过浏览器生成的CheckBox没有value属性,则可以自行添加,
clientID的生成以及Checked属性的添加 http://www.cnblogs.com/inforasc/archive/2009/12/07/1618277.html
总结:好久不用的知识,好快就忘记哦。温习需要....
标签:
原文地址:http://www.cnblogs.com/pyman/p/5060252.html