0

I generate my check boxes dynamically:

for (int i = 0; i < dtCommon.Count; i++)
{
    CheckBox newBox = new CheckBox();
    newBox.Text = dtCommon[i].userName;
    newBox.CssClass = "cbox";
    if (dtCommon[i].isAlreadyRequired > 0 )
    {
        newBox.CssClass = "cbox highlighted";
        newBox.Checked = true;
    }
    ApprovalSelectPanel.Controls.Add(newBox);
}

And when the save button is pressed I call this function:

protected void SaveUsers(object sender, EventArgs e)
{

}

How do I know which check boxes the user has checked?!

2 Answers 2

1

You could loop through the ApprovalSelectPanel.Controls and cast them back to the corresponding CheckBox type and verify the Checked property.

Sign up to request clarification or add additional context in comments.

1 Comment

Just be sure that your not regenerating the checkboxes on page_load without checking page.ispostback or you'll get crazy results / errors.
0

I think it is better to use CheckBoxList Within the ApprovalSelectPanel instead of add it in the runtime and in the runtime do the following

        CheckBoxList1.DataSource = dtCommon;
        CheckBoxList1.DataMember = "userName";
        CheckBoxList1.DataBind();

To know which one is selected do the following

          foreach(ListItem item in CheckBoxList1.Items)
            if (item.Selected)
            {
                //Do any action
            }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.