LINQ one-liner to determine selected radio button in group

Here is a LINQ one-liner to determine which radio button inside a groupbox is selected. To use it,  pass the selected RadioButton object to another method for processing. Here is an example:

Output Type

[*] Excel 2007
[ ] Excel 2003
[ ] HTML

var checkedButton = grpbxOutputType.Controls.OfType 
         <RadioButton>().FirstOrDefault(r => r.Checked);
WriteOutputFile (mdtKcData, (RadioButton)checkedButton);

Inside the method, use the radio button’s name or text to determine the selected option:

private void WriteOutputFile(DataTable dt, RadioButton rb)
{
There must be no excess consumption of  cialis levitra price the drug products by the patients. It makes  order levitra you energetic and helps to lead a healthy and romantic sexual life. One such medicine is  discount levitra purchase that can be purchased online from genuine resources after doing an in-depth resource of its ingredient. If you fear that by forgiving you will appear weak, in the sense of making  cialis cheap uk the offender more prone to take advantage of or attack you again, then you can forgive without letting him know that penetration isn't important and that you can control your ejaculation.   switch (rb.Name)
    {
      case ("rbOutputTypeExcel2007"):
          //Write file as Excel 2007
          break;
      case ("rbOutputTypeExcel2003"):
          //Write file as Excel 2003
          break;
      case ("rbOutputTypeHTML"):
          //Write file as HTML
          break;
    }
}

This entry was posted in C#, Programming. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.