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

In this code I want to add checkboxlist selected items to string array "selecteditems[i]" here using "selecteditems[i]" I need to bind in this code and show to only selected items

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'");
                }
            } 
2
  • I don't really understand the part with directories thing. Could you explain a bit more on what are you trying to achieve and how's that related to your question? Commented Apr 18, 2014 at 8:26
  • in my project one folder is there in that conains many folders like a,b,c,d and if i select a,b it should be show it in array only selected Commented Apr 18, 2014 at 8:54

1 Answer 1

4

Did you mean this?

var selecteditems = chbindustry.Items.Cast<ListItem>().Where(i=>i.Selected).Select(i=>i.ToString()).ToArray();
Sign up to request clarification or add additional context in comments.

3 Comments

i want it to add only selecterd items in array
its showing error Error 84 'System.Web.UI.WebControls.ListItemCollection' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'System.Web.UI.WebControls.ListItemCollection' could be found (are you missing a using directive or an assembly reference?) G:\DPOasPrinted\NewDPOcopy\NewDPOcopy\BCGallery.aspx.cs 88 41 NewDPOcopy
I did not know that Itemsis an object of ListItemCollection type. I've updated my answer, please check it again and let me know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.