Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have create dynamically three html radio button

In C# I need check all radio buttons are selected or not

C#
<input type="radio" name="Answer" id="radiodynamic1">
<input type="radio" name="Answer" id="radiodynamic2">
<input type="radio" name="Answer" id="radiodynamic3">



I have count

C#
for (int i = 1; i <= 3; i++)
              {
                  if (Request["radiodynamic" + i] != null)
                  {
// here how can i check radio button is selected or not

}

}


but it will not work properly

how can i check if radio buttons are selected or not
Please help me
Posted
Comments
Sampath Lokuge 14-Apr-14 8:48am    
Why can't you do it on client side by using jquery ?
Murugesan22 14-Apr-14 8:51am    
I have store to database via XML that time i need to check
Suk@nta 14-Apr-14 9:25am    
check the solution 2 might it help you

C#
add below property to the radio buttons and check the checked property in code behin

<input type="radio" id="radioExample1" runat="server" />

//code behind 
if (radioExample1.Checked)
{
     //write your code here
}

//let me know whether it helps you or not
 
Share this answer
 
You should attach a Javascript onclick event handler to each button:

JavaScript
<input type="radio" name="Answer" onclick="answer_click(this);" value="1">
<input type="radio" name="Answer" onclick="answer_click(this);" value="2">
<input type="radio" name="Answer" onclick="answer_click(this);" value="3">


Somewhere, define the Javascript function answer_click:

JavaScript
function answer_click ( radio_button )
  {
  switch ( radio_button.value )
    {
    case 1:
      code block 1
      break;

    case 2:
      code block 2
      break;

    case 3:
      code block 3
      break;

    default:
      code block for when radio_button.value is not 1, 2, or 3 
      break;
    }
 
Share this answer
 

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