Click here to Skip to main content
15,896,367 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
e.g. I have two checkBoxes namely CS and VB and i just want to know which one is selected using code behind.
Posted
Comments
Aravindba 27-Jul-15 5:20am    
not understand, u have 2 chekbox ? using which event u need to check which checkbox is checked ?

If suppose you have chkCS and chkVB as checkboxes (assuming they are "input" type and are accessible from server side) then you can use the following code to check if they are checked or not:

C#
if (chkCB.Checked == true)
{
    Console.Write("checkbox CS is checked");
}
else{
    Console.Write("checkbox CS is NOT checked");
}


Same way for chkVB.
 
Share this answer
 
You can try this-
C#
bool chkStatus = (Request.Form["YourCheckboxId"] == "on") ? true : false;


Hope, it helps :)
 
Share this answer
 
Hi Try this
ASP.NET
<asp:CheckBox runat="server" text="CS" OnClick="alert('CS');" />
<asp:CheckBox runat="server" text="VB" OnClick="alert('VB');" />


or try this


ASP.NET
 function gh(msg) {
            alert("You are clicked : " + msg);
        }


<asp:CheckBox ID="CheckBox1" runat="server" Text="VB" OnClick="gh('VB');" />
<asp:CheckBox ID="CheckBox2" runat="server" Text="CS" OnClick="gh('CS');" />

Regards
Aravindb
 
Share this answer
 
v4
Comments
Aravindba 27-Jul-15 5:49am    
solution updated check second option.

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