cancel check from checkBox
I have some checkBox in my page,
I want that the user checked maximum data but no more,
how can I cancel the select option.
here is my code:
PHP Code:
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
int select = 0;
int max =3;
if (max > 0)
{
for (int i = 0; i < checkBoxGrid.Items.Count; i++)
{
CheckBox cb = (CheckBox)checkBoxGrid.Items[i].FindControl("CheckBox1");
if (cb.Checked)
{
select++;
if (max == select)
{
//HERE I WANT TO CANCEL
}
}
}
}
}
thanks!
Re: cancel check from checkBox
Re: cancel check from checkBox
Not very elegant but you could use this:
Code:
select++;
if (max == select)
{
//HERE I WANT TO CANCEL
((CheckBox)sender).Checked = false;
}
senthilkumartd: Your method won't cancel the checkbox that was last checked but the checkbox that was last evaluated that made the count equal max.