填充复选框列表 [英] Populating a Checkbox list

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

问题描述

我正在尝试从目录列表中填充复选框列表.文件夹中只有四个文件,但是每个文件nbame出现1000次. ..
下面是代码:

Im trying to p[opulate a checkbox list from the directory list.There are only four files in the folder but each file nbame appears 1000 times..any solution to it..i just wana display a file name onces....
below is the code:

string[] files = Directory.GetFiles(Server.MapPath(".") + @"\NewFolder1");

                   foreach (string file in files)
                   {
                       chklist.Items.Add(new ListItem(Path.GetFileName(file), file));
                       RemoveDuplicateItem2(chklist);
                       //chklist.Items.Add(new ListItem(Path.GetFileName(file), file));
                   }


RemoveDuplicateItem2功能可删除重复的行以及文件路径,因此我无法下载文件...


the RemoveDuplicateItem2 fuctions removes the duplicate rows as well as the file path so i cant download the files......

推荐答案

1)正如Wes所说,在开始foreach循环之前,请调用chklist.Clear(),以便在启动时拥有一个干净的状态.
2)不要只是将所有内容添加到chklist控件中,然后尝试删除重复项.将项目添加到控件之前,请检查该项目是否已经存在.如果是这样,请忽略它.如果没有,请添加它.这是一种更有效的方法.
1) As Wes has alluded to, call a chklist.Clear() before you begin your foreach loop so that you have a clean slate when you start.
2) Don''t just add everything to the chklist control and then try to remove duplicates. Before you add an item to the control, check if that item already exists. If it does, just ignore it. If it doesn''t, add it then. It is a much more efficient way.


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

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