C# 如何将选中的复选框列表项添加到字符串数组? public string[]selected() { string[]selecteditems=新字符串[chbindustry.Items.Count]; 对于(int i=0;ii.Selected).Select(i=>i.ToString()).ToArray();

C# 如何将选中的复选框列表项添加到字符串数组? public string[]selected() { string[]selecteditems=新字符串[chbindustry.Items.Count]; 对于(int i=0;ii.Selected).Select(i=>i.ToString()).ToArray();,c#,asp.net,C#,Asp.net,在这段代码中,我想使用“selecteditems[I]”将复选框列表中的选定项添加到字符串数组“selecteditems[I]”中。我需要在这段代码中绑定并仅显示选定项 public string[] selected() { string[] selecteditems = new string[chbindustry.Items.Count]; for (int i = 0; i < chbindustry.Items.Count-

在这段代码中,我想使用“selecteditems[I]”将复选框列表中的选定项添加到字符串数组“selecteditems[I]”中。我需要在这段代码中绑定并仅显示选定项

    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;
    }
foreach(子目录入口中的字符串)
{
DirectoryInfo d=新的DirectoryInfo;
对于(inti=1;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().Where(i=>i.Selected).Select(i=>i.ToString()).ToArray();
你是这个意思吗

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().Where(i=>i.Selected).Select(i=>i.ToString()).ToArray();
你是这个意思吗

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().Where(i=>i.Selected).Select(i=>i.ToString()).ToArray();
你是这个意思吗

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().Where(i=>i.Selected).Select(i=>i.ToString()).ToArray();


我希望它只在数组中添加selecterd项,显示错误84'System.Web.UI.WebControl.ListItemCollection'不包含'Where'的定义,并且没有扩展方法'Where'可以找到'accepting a first Parameter of type'System.Web.UI.WebControl.ListItemCollection'(是否缺少using指令或程序集引用?)G:\DPOasPrinted\NewDPOcopy\NewDPOcopy\BCGallery.aspx.cs 88 41 NewDPOcopy我不知道
Items
ListItemCollection
类型的对象。我已经更新了我的答案,请再次检查并让我知道。我希望它只在数组中添加selecterd项,显示错误84'System.Web.UI.WebControls.ListItemCollection'does不包含“Where”的定义,也没有扩展方法“Where”可以找到System.Web.UI.WebControl.ListItemCollection类型的“接受第一个参数”(是否缺少using指令或程序集引用?)G:\DPOasPrinted\NewDPOcopy\NewDPOcopy\BCGallery.aspx.cs 88 41 NewDPOcopy我不知道
Items
ListItemCollection
类型的对象。我已经更新了我的答案,请再次检查并让我知道。我希望它只在数组中添加selecterd项,显示错误84'System.Web.UI.WebControls.ListItemCollection'does不包含“Where”的定义,也没有扩展方法“Where”可以找到System.Web.UI.WebControl.ListItemCollection类型的“接受第一个参数”(是否缺少using指令或程序集引用?)G:\DPOasPrinted\NewDPOcopy\NewDPOcopy\BCGallery.aspx.cs 88 41 NewDPOcopy我不知道
Items
ListItemCollection
类型的对象。我已经更新了我的答案,请再次检查并让我知道。我希望它只在数组中添加selecterd项,显示错误84'System.Web.UI.WebControls.ListItemCollection'does不包含“Where”的定义,也没有扩展方法“Where”可以找到System.Web.UI.WebControl.ListItemCollection类型的“接受第一个参数”(是否缺少using指令或程序集引用?)G:\DPOasPrinted\NewDPOcopy\NewDPOcopy\BCGallery.aspx.cs 88 41 NewDPOcopy我不知道
Items
ListItemCollection
类型的对象。我已经更新了我的答案,请再次检查并让我知道。我真的不明白目录部分的事情。你能解释一下你想实现什么吗这与你的问题有什么关系?在我的项目中,有一个文件夹包含许多文件夹,如a、b、c、d,如果我选择a、b,它应该是以数组形式显示,只选择a。我真的不理解目录部分。你能解释一下你想实现什么,以及这与你的问题有什么关系吗?在我的公关中项目一个文件夹包含很多文件夹,比如a,b,c,d,如果我选择a,b,它应该显示在数组中,只选择d。我真的不理解目录部分的内容。你能解释一下你想实现什么,以及这与你的问题有什么关系吗?在我的项目中,一个文件夹包含很多f像a,b,c,d这样的老年人,如果我选择a,b,它应该显示在数组中,只选择d。我真的不理解目录的部分。你能解释一下你想实现什么,以及这与你的问题有什么关系吗?在我的项目中,有一个文件夹包含许多文件夹,如a,b,c,d,如果我选择a,b,它应该d仅在选定的数组中显示它