如何在asp.net c#checkboxlist中禁用某些值 [英] How to disable certain values in asp.net c# checkboxlist

查看:92
本文介绍了如何在asp.net c#checkboxlist中禁用某些值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个复选框列表中有几个国家/地区。



我的问题是,如果用户必须选择1个特定国家(南非 - SA),则必须禁用列表中的其他国家/地区复选框。



如果国家/地区未选择南非(SA),然后必须启用其余复选框。



此复选框列表按字母顺序排列,因此我遇到了禁用问题的问题国家南非之前的复选框。



我已尝试过for循环但面临一些问题。



Hi,

I have a checkboxlist that have a few countries populated in them.

My problem is that if a user has to select 1 particular country (South Africa - SA) then the other countries checkboxes in the list must be disabled.

If the country South Africa (SA) is not selected then the rest of the checkboxes must be enabled.

Also this checkboxlist is going in alphabetical order so I was having issues with disabling the the checkboxes before the country South Africa.

I have tried it with for loops but faced some issue.

protected void cblCountryAdd_SelectedIndexChanged(object sender, EventArgs e)
       {
           for (int i2 = 0; i2 < cblCountryAdd.Items.Count; i2++)
           {
               if (cblCountryAdd.Items[i2].Selected == true)
               {
                   if (cblCountryAdd.Items[i2].Value == "SA")
                   {
                       cblCountryAdd.Items[i2].Selected = false;
                   }
                   else
                   {
                       cblCountryAdd.Items[i2].Selected = true;
                   }
               }
           }

       }







如果有人可以帮我这个我会很感激。



谢谢




if anyone could help me with this I would appreciate it.

thanks

推荐答案

你应该这样做:





You should do this:


bool SA_selected = cblCountryAdd.Items["SA"].Selected
for (int i2 = 0; i2 < cblCountryAdd.Items.Count; i2++)
{
cblCountryAdd.Items[i2].Enabled = !SA_selected
}







也就是说,检查是否选择了SA并启用或禁用所有项目 - 您必须添加支票而不是禁用SA项目:)



假设禁用复选框也必须取消选中,哟你需要添加




That is, check if SA is selected and enable or disable all items - you would have to add a check not to disable SA item :)

Assuming disabled checkboxes have to be also unselected, you need to add

cblCountryAdd.Items[i2].Selected = false;


使用jQuery切换与南非选中状态相关的其他复选框的禁用状态复选框。例如,

Use jQuery to toggle the disabled state of other checkboxes with respect to the checked state of the South Africa checkbox. E.g.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>


(document).ready(function(){
(document).ready(function(){


这篇关于如何在asp.net c#checkboxlist中禁用某些值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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