不可选择的checkboxlist项不起作用 [英] Not selectable checkboxlist item not working
本文介绍了不可选择的checkboxlist项不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了一个我遇到的问题,我已经克服了90%的问题。
我有一个复选框列表,其中包含一些项目,如果选择了1个特定值,则不能选中其余的复选框。
导致此条件的值位于列表中的位置6,并且对于之前的项目可以正常工作,但仍可以选择位置之后的项目。
Hi,
I have a problem that I am faced with, I have overcome 90% of the issue.
I have a checkboxlist that has a few items, if 1 specific value is selected then the rest of the checkboxes must not be selected.
the value that causes this condition is at position 6 in the list and it works fine for the items before it, but the items after position can still be selected.
bool SA_selected = cblCountryAdd.Items[6].Selected;
if (SA_selected)
{
for (int i2 = 0; i2 < cblCountryAdd.Items.Count; i2++)
{
if (cblCountryAdd.SelectedValue != "ZA")
{
cblCountryAdd.Items[i2].Selected = false;
}
if (cblCountryAdd.Items[i2].Value == "ZI")
{
cblCountryAdd.Items[i2].Selected = false;
}
//else
//{
// cblCountryAdd.Items[i2].Selected = false;
//}
}
推荐答案
您好,
我不知道是否你的逻辑是否正确,但它似乎是你的字符串比较的问题。尝试更改运算符!=和== to!string.Equals和string.Equals:
Hello,
I don't know whether your logic is correct or not, but it seems to be a problem with your string comparisons. Try changing operator != and == to !string.Equals and string.Equals:
bool SA_selected = cblCountryAdd.Items[6].Selected;
if (SA_selected)
{
for (int i2 = 0; i2 < cblCountryAdd.Items.Count; i2++)
{
if (!"ZA".Equals((String)cblCountryAdd.SelectedValue))
{
cblCountryAdd.Items[i2].Selected = false;
}
if ("ZI".Equals((String)cblCountryAdd.Items[i2].Value))
{
cblCountryAdd.Items[i2].Selected = false;
}
}
关于字符串比较的更多信息:http://stackoverflow.com/questions/1659097/why-would-you-use-string-equals-over [ ^ ]
试试这个jQuery示例并根据您的需要进行调整:
Try this jQuery sample and adapt it to your need:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm15.aspx.cs" Inherits="WebApplicationCS2.WebForm15" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
(document).ready(function(){
var
(document).ready(function () { var
这篇关于不可选择的checkboxlist项不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文