如何将checkboxlist选中的项添加到字符串数组?

时间:2014-04-18 08:19:54

标签: c# asp.net

    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;
    }

在这段代码中我想将checkboxlist选中的项添加到字符串数组&#34; selecteditems [i]&#34;这里使用&#34; selecteditems [i]&#34;我需要绑定此代码并仅显示选定的项目

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'");
                }
            } 

1 个答案:

答案 0 :(得分:3)

你的意思是?

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