如何禁用Checklistbox asp.net中的项目 [英] how to disable items in Checklistbox asp.net

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

问题描述

我有一个包含一些项目的Checklistbox。绑定数据时,需要禁用几个项目。如何在asp.net中执行此操作

解决方案

如果您只想清除所选项目,请使用以下代码:

ListBox1.ClearSelection();

//

foreach (ListItem listItem in ListBox1.Items)
{
listItem.Selected = ;
}
如果您的意思是删除项目,那么 代码 你..

List< ListItem> itemsToRemove = new List< ListItem>();

foreach (ListItem listItem in ListBox1.Items)
{
if (listItem.Selected)
itemsToRemove.Add(listItem);
}

foreach (ListItem listItem in itemsToRemove)
{
ListBox1.Items.Remove(listItem);
}


您可以获得检查列表框的特定项目并将其正确设置为False

一个例子是

 CheckBoxList1.Items [ 0 ]。启用=  false ; 


I have a Checklistbox with some items. Few Items need to be disabled when the data is bound. How to do this in asp.net

解决方案

If you just want to clear the selected items then use the code below:

        ListBox1.ClearSelection();

        //or

        foreach (ListItem listItem in ListBox1.Items)
        {
            listItem.Selected = false;
        }
If you mean to what to actually remove the items, then this is the code for you..

        List<ListItem> itemsToRemove = new List<ListItem>();

        foreach (ListItem listItem in ListBox1.Items)
        {
            if (listItem.Selected)
                itemsToRemove.Add(listItem);
        }

        foreach (ListItem listItem in itemsToRemove)
        {
            ListBox1.Items.Remove(listItem);
        }


You can get perticular item of check list box and set its Enabled properly to False
One example is

CheckBoxList1.Items[0].Enabled = false;


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

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