2

Sorry for my poor english.

On my ASP.NET website, I'm importing a softwares list from a SQL table, looking like this, but in reality much longer :

Microsoft Application Error Reporting<br><br />Microsoft Application Error Reporting<br><br />Microsoft Office Professional Plus2010<br><br />Microsoft Office OneNote MUI (English) 2010<br><br/>Microsoft Office InfoPath MUI (English) 2010<br><br />Microsoft Office Access MUI (English) 2010<br><br />Microsoft Office Shared Setup Metadata MUI (English) 2010<br><br />

To create the checkbox, I did it this way :

  int i = 1;
            CheckBoxList1.Items.Clear();
            foreach (char c in Resultat)
            {
                string value = ""+i;
                if (c == '/')
                {
                    CheckBoxList1.Items.Add(value);
                    i++;
                }
            } 

And it looks like this :

ScreenWebsite ( Sorry, I don't have enough reputation to directly post the picture )

What I'd like to do now is performing a specific command for each checkbox I... check. I don't know how to select a specific checkbox as my checkboxes have no ID.

Thanks a lot for you help, and sorry again for my english.

4

1 回答 1

1

尝试这个:

void CheckBoxList1_SelectedIndexChanged(Object sender, EventArgs e) 
      { 
   foreach var item in CheckBoxList1.Items
    {
       if(item.Selected)
       {
         string value = item.Text;
         'DO SOMETHING
       }
    }
}

你也可以这样做:

void CheckBoxList1_SelectedIndexChanged(Object sender, EventArgs e) 
      {

         for (int i=0; i<checkboxlist1.Items.Count; i++)
         {

            if (checkboxlist1.Items[i].Selected)
            {

               string value = checkboxlist1.Items[i].Text;

            }

         }

      }
于 2012-06-01T07:59:04.653 回答