如何在asp.net中查找复选框列表是否被选中
如何在 asp.net 中的复选框列表中获取选定的索引。我应该循环查找列表框是否被选中,或者我可以不这样做就知道吗?我想这样做
如果(选中复选框列表) {做这个} 别的 {do this}
如何在asp.net中查找复选框列表是否被选中
int roleselected = ckl_EditRole.Items.SelectedIndex;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 CheckBoxList,
SelectedIndex
只会为您提供 CheckBoxList 中第一个选定的索引。如果不是 -1,则表明已选择某些内容。这可能足以满足您的需求。但是,由于 CheckBoxList 可以有多个选择,因此您可能希望循环遍历项目并查找选定的项目。
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.But, since the CheckBoxList can have multiple selections, you probably want to loop through the Items and look for the selected ones.
如果您的目的是获取代码给出的所选复选框的索引,您也可以通过 Linq(不带 forloop)来实现此目的,如下所示。
该语句将返回一个 int 数组,其中包含所选复选框的索引。
If your intention is to get index of the selected checkbox as given by your code, you can also achieve this via Linq(without forloop) as below.
This statement will return an array of int which will contain the index of the check boxes that are selected.