Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i think my subject is very complete explanation :)


thank u for time
Posted
Comments
[no name] 7-Nov-12 5:11am    
use mutually exclusive checkboxes in ajax
sahrarainmelody 7-Nov-12 5:18am    
excuse me .. but i dont know ajax
[no name] 7-Nov-12 5:54am    
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/MutuallyExclusiveCheckBox/MutuallyExclusiveCheckBox.aspx
[no name] 7-Nov-12 5:55am    
windows/web....?

you can do something like this..

C#
if(checkbox1.Checked)
checkbox2.checked=false;
else if(!checkbox1.checked)
checkbox2.checked=true;
 
Share this answer
 
v2
Comments
sahrarainmelody 8-Nov-12 3:30am    
it should be written for chbox1,chbox2 ... both of them
thanks
vinod kumar from bangalore 28-Nov-12 4:58am    
depends upon ur requirement.
if u want that when chbox1 is checked then chbox2 has to be unchacked and if chbox1 is unchecked then chbox2 has to be checked..
in that case you have to write for both .
else write for that chbox on which you want to perform that requied action .
thanks
Since, you have selected only C# tag, I assume, its windows application.
There are two options now.
1. You can use CheckedListBox control (if you are in design phase) and there you can select property so it allows only one check box selection
2. You need to write code on form load
C#
ChkBox1.CheckedChanged += new EventHandler(OnCheckedChanged);
ChkBox2.CheckedChanged += new EventHandler(OnCheckedChanged); 


Now all check box will point to same event handler function.

In this even handler, you write

C#
private void OnCheckedChanged(object sender, EventArgs e)
{
  CheckBox clickedCheckBox = (CheckBox) sender;
  if(clickedCheckBox.Checked)
  {
    if(clickedCheckBox.Name = "ChkBox1";
       ChkBox2.Checked = false;
    else
       ChkBox1.Checked = false;
  }
}

The only problem with second solution, it is going to be nightmare if you have more than 2-3 checkboxes.

Hope that helps. If it does, mark it as solution.
Thanks
Milind
 
Share this answer
 
Comments
sahrarainmelody 8-Nov-12 3:36am    
fortunately i have just 2 chkboxes :) and it works well
MT_ 8-Nov-12 3:44am    
Glad it helped.
ok you have to write some code:
C#
if(chkbox1.checked==true)
{
 chkbox2.checked==false;
 chkbox3.checked==false;
}
else if(chkbox1.checked==false)
{
  chkbox2.checked==true;
 chkbox3.checked==true;
}


Write this code on checked event of chkbox1
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 8-Nov-12 1:57am    
It won't even compile. My vote of 1, sorry.
--SA
sahrarainmelody 8-Nov-12 3:25am    
must be written a code like this for chkbox2 too ....
it works for me
tnx
sariqkhan 19-Nov-12 12:45pm    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900