Sunday, July 5, 2009

CheckBoxList in ASP.NET

To retrieve the input information from a check box list, traverse through all the items in the list and determine if the value is set to true (i.e. selected).

C# Code:
protected void btnSubmit_Click(object sender, EventArgs e) {
  
    label1.Text = "You selected: ";
    foreach (ListItem li in checkBoxList.Items) {
      if (li.Selected == true) label1.Text += li.Text + " ";
    }
}

No comments:

Post a Comment