如何检查DropDownCheckBox何时选择全部或不选择 [英] How to Check when DropDownCheckBox Select All or Not

查看:62
本文介绍了如何检查DropDownCheckBox何时选择全部或不选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

这是我的代码..

如果选择all表示Class_Cd为Null,..否则只选择代码它将存储在这里Class_Cd



Hi all,
This is my Code..
If select all means "Class_Cd" is Null,..Otherwise selected code only it will store here "Class_Cd"

int i = 0;
        foreach (ListItem item in (Class_DropDownCheckBoxes as ListControl).Items)
        {
            if (item.Selected)
            {
                if (i == 0)
                {
                    Class_Cd = "'" + item.Text.Substring(0, 1).ToString() + "'";
                }
                else
                {
                    Class_Cd = Class_Cd + ',' + "'" + item.Text.Substring(0, 1).ToString() + "'";
                }
                i = i + 1;
            }
        }





请帮助我..



Please help me..

推荐答案

如何检查DropDownCheckBox何时选择全部?



如果您使用的是ListView控件,则可以将SelectedIndices.Count属性值与Items.Count属性值。 ListControl没有SelectedIndices属性。如果继续使用ListControl,则必须遍历ListControl中的项目并计算有多少Items(x).Selected属性为true。
How to Check when DropDownCheckBox Select All or Not?

If you were using a ListView control, you could compare the SelectedIndices.Count property value with the Items.Count property value. The ListControl does not have a SelectedIndices property. If you continue to use ListControl, you will have to iterate through the items in the ListControl and count how many Items(x).Selected properties are true.


这是您可以使用的示例代码请参阅检查所选项目计数。

希望这会给你一些想法。



This is the sample code you can refer to check the selected items count.
Hope this would give you some idea.

string itemText = string.Empty;
int i = 0;
// iterate through the items in the CheckBoxList1.
// count only the selected items. not worry about the unselected items.
foreach (ListItem item in (CheckBoxList1 as ListControl).Items)
{
    if (item.Selected)
    {
        itemText += item.Text + ",";
        i++;
    }
    else
    {
        itemText += item.Text + ",";
    }
}
// Check the total items count in the CheckBoxList1 and the i count.
// if both are same then set the itemText to null.
if (CheckBoxList1.Items.Count == i)
{
    itemText = null;
}


这篇关于如何检查DropDownCheckBox何时选择全部或不选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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