如何从复选框列表中获取选中的复选框项目 [英] how to get selected checkbox item from check box List

查看:138
本文介绍了如何从复选框列表中获取选中的复选框项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从复选框列表中获取选定的复选框项

how to get selected checkbox item from check box List

推荐答案

string strchecked="";
 for (int i = 0; i < chk1.Items.Count; i++)
                {
                    if (chk1.Items[i].Selected)
                    {                      
			if(strchecked.Trim()==string.empty())
			{
				strchecked=chk1.Items[i].Text;	
			}
			else
			{
				strchecked=strchecked+","+chk1.Items[i].Text;	
			}

                    }
                }




您可以尝试使用此代码.
Hi,

you can try this code.
CheckBoxList1.SelectedItem



但是checkboxlist是您可以选择多个选项的情况,在这种情况下,它仅返回

较低的项目表示

所选项目中排在最前面的项目.

如果要获取所有选定的项目,则



But checkboxlist is you can select multiple options in that case it returns only

lower item that means

top selected item in your selected items.

If you want to get all selected items then

foreach (ListItem boxItem in CheckBoxList1.Items)
{
  

  if (boxItem.Selected == true)
  {
    categoryID.Add((string)boxItem.Value);
   
  }
}



最好的



All the Best


以这种方式尝试

try in this way

if (chkboxlist.Items[0].Selected == true)
{
//do something you want 
}
else if (chkboxlist.Items[1].Selected == true)
{
//do something you want 
}
else if (chkboxlist.Items[2].Selected == true)
{
//do something you want 
}


这篇关于如何从复选框列表中获取选中的复选框项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆