Monday, March 26, 2012

loop controls ?

what is the best way to loop through a set of controls?
What I am trying to do is change all the checkbox output to yes and no.........forexample i have a checkbox.checked = false I want to input no into a database or yes if its true.........i have like over 50 checkbox.......so is there a easy way to loop through all the controls ? thanks

Here is a thought.
Say you are having all your checkboxes within a server form control with id Form1. You can loop through the collection Form1.Controls and check the type of each control. If it is a System.Web.UI.WebControls.CheckBox, you can then cast the control to the CheckBox type and access its Checked property.

0 comments:

Post a Comment