Forum guidelines
AuthorQuestion
radio buttons!
Posted By yongsim yongsim on 15 Aug 2005
hi all!i have a form which has a group box and inside the group box have five radio buttons(one is selected by default).At the same time it also have a "OK" button at the form.So when i click on "Ok" button it will sent the value out..Does anybody can provide my some guideline or code..Thanks in advance! 
 

AuthorReply
Re: radio buttons!
Posted By Solitaire on 17 Aug 2005  

You didn't state the language.  Here is a sample written in VB:


Private
Sub btnSelect_Click(ByVal sender As System.Object, _

                  ByVal e As System.EventArgs) Handles btnSelect.Click

        Dim radnumg As Integer

        Select Case True

            Case rdoGroup1.Checked

                radnumg = 1

            Case rdoGroup2.Checked

                radnumg = 2

            Case rdoGroup3.Checked

                radnumg = 3

            Case rdoGroup4.Checked

                radnumg = 4

            Case rdoGroup5.Checked

                radnumg = 5

        End Select

        If radnumg = 0 Then

            lblGroup.Text = "No group radio button is checked."

        Else

            lblGroup.Text = "Group Radio Button # " & radnumg.ToString() & " is checked."

        End If

End Sub



and in C#:


private void btnSelect_Click(ByVal sender As System.Object,
   {ByVal e As System.EventArgs) Handles btnSelect.Click;

  int radnumg = 0;


  if (true == rdoGroup1.Checked)
  {

    radnumg = 1;

  }

  else if (true == rdoGroup2.Checked)
  {

    radnumg = 2;

  }

  else if (true == rdoGroup3.Checked)
  {

    radnumg = 3;

  }

  else if (true == rdoGroup4.Checked)
  {

    radnumg = 4;


  }

  else if (true == rdoGroup5.Checked)
  {


    radnumg = 5;

  }

  if (radnumg == 0)
  {

   lblGroup.Text = "No group radio button is checked.";

  }
  else
  {

   lblGroup.Text = "Group Radio Button # " + radnumg.ToString() + " is checked.";

  }

}






 


C# Corner Annual Conference 2016

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.