Monday, September 9, 2013

Find Selected CheckBoxes in CheckBoxList C# ASP.Net

Find selected Checkboxes in a checkboxlist is quite easy using the foreach loop

1. First Create a checkboxlist and assign it's id="chklist"

2. Insert some random data inside your checkboxlist

3. Now using the following C# code you can find the selected checkboxlist

   1:   string a = "";
   2:              foreach (ListItem ls in chklisk.Items)
   3:              {
   4:                  if (ls.Selected)
   5:                  {
   6:                      a = a + ls.Text;
   7:                  }
   8:              }
The purpose of this foreach loop is to iterate through all the checkbox, if any checkbox is found selected than it's text will be stored in a sting called a

I hope it was informative for you, and I would like to thank you for reading

No comments:

Post a Comment