I'm currently trying to get a count of a CheckBoxList to use in conjunction with an if and else statement for a project. If the count is not equal to 2 I have a label that prompts the user to select two modules but the count isn't being calculated properly. Any help would be appreciated. Here is the code in question:
protected void RegisterButton_Click(object sender, EventArgs e) {
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["UniString"].ConnectionString);
//This integer will hold the number of modules selected
Int32 amount = 0;
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
//amount will increment each time a module checkbox is checked
if (CheckBoxList1.Items[i].Selected)
{
amount = amount++;
}
//If amount is not equal to 2 the code below will run
if (amount != 2)
{
//If the number of modules selected is not equal to 2 then this message is displayed and the background of the label in the markup is turned red to draw attention
ModuleSelectionMessage.Text = "Please select 2 modules to successfully register";
ModuleSelectionMessage.BackColor = System.Drawing.Color.Red;
}
else
{...
Aucun commentaire:
Enregistrer un commentaire