复选框列表中的选定项目 [英] Selected items on checkboxlist

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

问题描述

大家好,



我有一个复选框列表。在选择几个项目时,值将转到数据库,但在编辑模式下,我希望所有这些项目都应显示在我在数据库中提交的页面加载中。 (复选框列表项应该显示为选中。)





帮我plz。

谢谢。

解决方案

假设您有一个已绑定到复选框列表的Id和Text属性。选择后,Id将存储到数据库中。



因此,在页面加载时,获取现有ID并迭代它们并将checkboxlist中的相应项设置为选中。



 CheckBoxList chkList =  new  CheckBoxList();  //  这将是复选框列表 
List< int> ids = new List< int>(); // 从数据库填充此列表
/ / 迭代此列表以便仅选择这些字段
ids.ForEach(id = >
{
var item = chkList.Items.FindByValue(id.ToString());
< span class =code-keyword> if ( null != item)
item.Selected = true ;
});
< / int > < / int >


hi all,

I am having a checkboxlist. On selection of few items, values is going to the database but in edit mode i want that all those items should be shown on page load which i have submitted in database. (The checkboxlist items should be shown selected.)


help me plz.
Thanks.

解决方案

Assuming you have an Id and a Text property which you have binded to the checkbox list. Upon selection, the Id would get stored to the database.

So on page load, get the existing ids and iterate them and set the corresponding items in checkboxlist as checked.

            CheckBoxList chkList = new CheckBoxList();  // This will be the checkboxlist
            List<int> ids = new List<int>();    // Populate this list from DB
            // Iterate over this list so as to select only these fields
            ids.ForEach(id =>
            {
                var item = chkList.Items.FindByValue(id.ToString());
                if (null != item)
                    item.Selected = true;
            });
</int></int>


这篇关于复选框列表中的选定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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