1
public string[] selected()
{

    string[] selecteditems = new string[0];
    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 it in below 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'");
                }
            } 

1 Answer 1

1

try with this.

public string[] selected()
{
    string strTemp = "";
    for (int i = 0; i < chbindustry.Items.Count - 1; i++)
    {
        if (chbindustry.Items[i].Selected)
        {
            strTemp += chbindustry.Items[i].Text.ToString() + ",";
        }
    }
    string[] selecteditems = strTemp.Split(','); 
    return selecteditems;
}

......... ......... Edit 1:

string[] selecteditems = selected();
foreach (string s in subdirectoryEntries)
{
    if (!string.IsNullOrEmpty(s) && selecteditems.Contains(s)) //Folder is selected in ListItem
    {
        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'");
        }
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

in below code it showing selected folder so how can i put in that code only selected items
in array its taking another blanck array??
I thought that your both code snippet in different methods. If you stored in to the another variable then you will get better performance. If you will write 'selected().Contains(s)', you will get performance issue.

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.