Results 1 to 3 of 3

Thread: cancel check from checkBox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    194

    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 senderEventArgs e)
        {
            
    int select 0;
            
    int max =3;
            if (
    max 0)
            {
                for (
    int i 0checkBoxGrid.Items.Counti++)
                {
                    
    CheckBox cb = (CheckBox)checkBoxGrid.Items[i].FindControl("CheckBox1");
                    if (
    cb.Checked)
                    {
                        
    select++;
                        if (
    max == select)
                        {
                          
    //HERE I WANT TO CANCEL
                  
                        
    }
                    }
                }
            }
          
        } 
    thanks!

  2. #2
    Addicted Member senthilkumartd's Avatar
    Join Date
    Feb 2005
    Posts
    206

    Re: cancel check from checkBox

    Try this. I am not sure.
    Code:
    cb.checked=false
    God has been pleased to place as a king or cobbler do the work sincerely

  3. #3
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width