如果在asp.net中是否选择该复选框列表怎么找 [英] how to find if the check box list is selected or not in asp.net

查看:92
本文介绍了如果在asp.net中是否选择该复选框列表怎么找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在asp.net一个复选框列表获取所选的索引。我应该通过循环来查找列表框中是否选择我可以知道没有这样做。我想这样做。

如果(的CheckBoxList选择)
{做这个}
其他
{做到这一点}

如何如果选中该复选框列表或找到不asp.net

  INT roleselected = ckl_EditRole.Items.SelectedIndex;


解决方案

有关的CheckBoxList,的SelectedIndex 会给你刚才在的CheckBoxList的一个选择的索引。如果它不是-1,被选中然后什么。这可能是足以让你在找什么。

 如果(ckl_EditRole.SelectedIndex!= -1)
{
// 做一点事
}

但是,因为的CheckBoxList可以有多种选择,你可能想通过项目环和查找选择的。

 的foreach(在ckl_EditRole.Items列表项LI)
{
    如果(li.Selected)
    {
        // 做一点事
    }
}

How to get selected index in a check box list in asp.net. Should I loop through to find whether the list box is selected or can i get to know without doing that. I want to do this

if(Checkboxlist selected) {do this} else {do this}

how to find if the check box list is selected or not in asp.net

int roleselected = ckl_EditRole.Items.SelectedIndex;

解决方案

For CheckBoxList, SelectedIndex will give you just the first selected index in the CheckBoxList. If it's not -1, then something was selected. This may be enough for what you're looking for.

if( ckl_EditRole.SelectedIndex != -1 )
{
// Do Something
}

But, since the CheckBoxList can have multiple selections, you probably want to loop through the Items and look for the selected ones.

foreach( ListItem li in ckl_EditRole.Items )
{
    if( li.Selected )
    {
        // Do Something
    }
}

这篇关于如果在asp.net中是否选择该复选框列表怎么找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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