CheckBoxList项目中的问题已检查 [英] Problem in CheckBoxList item checked

查看:112
本文介绍了CheckBoxList项目中的问题已检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要检查CheckBoxList项,我正在使用以下代码

To Checked CheckBoxList item I am using following code

string pyDetails = objBiltyDetails.BltPayDetails.ToString();
            string[] split = pyDetails.Split(',');
            foreach (string item in split)
            {

                //if (item != "")
                //{

                    CheckBxPayDetails.SelectedValue = item;

                //}
            }



项目中有两个值,但仅选中了一个复选框.请帮助



There are two values in item but only one check box is Checked. Please help

推荐答案

是的,显然枚举中的最后一项将被设置为SelectedValue,因为这就是您编码的内容.

如果尝试选择CheckBoxList下的所有复选框,请在foreach循环中尝试以下代码行:

Yes obviously the last item in the enumeration will be set as SelectedValue because that''s what you have coded.

If you are trying to select all checkboxes under the CheckBoxList, then try the below line of code in your foreach loop:

CheckBxPayDetails.Items.Add(new ListItem() { Text = item, Selected = true });


请忽略此答案-我假设使用CheckedBoxList而不是CheckBoxList.

如果查看CheckedBoxList的规范,您会发现不支持MultiSelection,因此无论如何它都不会起作用.即使您确实使用了可能选择两项的代码,例如
Please ignore this answer - I assumed CheckedBoxList rather than CheckBoxList.

If you look at the specification for CheckedBoxList you will see that MultiSelection is not supported, so it isn''t going to work anyway. Even if you did use code that might select two items, such as
CheckBxPayDetails.SelectedItems.Add(item);

(正如我所说,由于CheckedBoxList不支持多个选择,因此无法使用.

您确定要使用Select吗?还是您要使用Checked?

我正在尝试检查"

试试:

(Which as I said, won''t work because CheckedBoxList doesn''t support multiple selections.

Are you sure you want to use Select? Or are you trying to use Checked?

"I am trying to checked"

Try:

string pyDetails = objBiltyDetails.BltPayDetails.ToString();
string[] split = pyDetails.Split('','');
foreach (string item in split)
    {
    int index = CheckBxPayDetails.FindString(item);
    if (index >= 0)
        {
        CheckBxPayDetails.SetItemChecked(index, true);
        }
    }

您可能想先遍历它们,将检查状态设置为false-我不知道您的应用程序做什么!

You may want to loop through them all first, setting the check status to false - I don''t know what you app does!


这篇关于CheckBoxList项目中的问题已检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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