如何将选中的复选框列表项添加到字符串数组中

本文关键字:添加 数组 字符串 列表 复选框 | 更新日期: 2023-09-27 17:58:56

    public string[] selected()
    {
        string[] selecteditems = new string[chbindustry.Items.Count];
        for (int i = 0; i < chbindustry.Items.Count-1; i++)
        {
            if (chbindustry.Items[i].Selected)
            {
                selecteditems[i] = chbindustry.Items[i].Text.ToString();

                //string Va = string.Empty;
                //Va = chbindustry.Items[i].Text.ToString();
               // selecteditems[i] = Va;
            }
        }
        return selecteditems;
    }

在这段代码中,我想使用"selecteditems[I]"将复选框列表中的选定项目添加到字符串数组"selectditems[I]

foreach (string s in subdirectoryEntries)
            {
                DirectoryInfo d = new DirectoryInfo(s);
                for (int i = 1; i <= d.GetFiles().Length / 3; i++)
                {
                    selected();
                    Page.ClientScript.RegisterArrayDeclaration("ImgPaths", "'" + "BusinessCards/" + s.Remove(0, s.LastIndexOf('''') + 1) + "/" + i + ".jpg'");
                    Page.ClientScript.RegisterArrayDeclaration("refs", "'" + "DesignBCs.aspx?img=BusinessCards/" + s.Remove(0, s.LastIndexOf('''') + 1) + "/" + i + "&Side=2'");
                }
            } 

如何将选中的复选框列表项添加到字符串数组中

你是这个意思吗?

var selecteditems = chbindustry.Items.Cast<ListItem>().Where(i=>i.Selected).Select(i=>i.ToString()).ToArray();