Dynamica checkboxes and how to determine checked
Posted on 2007-04-04
Creating an ASP.Net 1.1 page in VS.net 2003
Here's what I am doing. I get a view of my dataset (Names, Addresses, etc).
Then I loop through each record in order to create a check box for that user and their email addy. This will give the end users a list of names that they can choose from in order to send their email to, check to send this person an email, uncheck not to send them the email.
Looks a little like this
To: Joe Smith [x]
To: Sanjay Patel [x]
To: Kris Karasek [x]
To: Anna Smith [x]
for(int c=_NumberOfRecipients-1; c>-1; --c)
dr = dv.Table.Rows[c];
//create a check box
CheckBox chkTo = new CheckBox();
chkTo.ID = dr["EmailAddress"].ToString();
chkTo.ToolTip = dr["EmailAddress"].ToString();
_names = "To: " + dr["FirstName"].ToString() + " " + dr["LastName"].ToString() + " ";
chkTo.Text = _names;
chkTo.Checked = true;
//add the chk box to the contact panel
//empty before next go round
_names = string.Empty;
then on the SUBMIT button, when the user goes to send the email, i try to loop through the check boxes (created above) in the panel, to see which check boxes are checked and which are not in order to build a TO: string of email addresses, it fails to find any check boxes.
foreach (System.Web.UI.Control c in this.iContact.Controls)
if ((c.GetType() == typeof(CheckBox)))
// is it a checkbox?
CheckBox chk = (CheckBox)c;
if (chk.Checked == true)
//build a TO string for emailing members
_EmailAddressesTo += chk.ID;
Any help on how to get the second loop to actually access each dynamically created checkbox would be appreciated:-)