views:

285

answers:

1

Hi, i have a listview with 2 or more radio button controls in each row of it and i want to findout if atleast one radiobutton selected on submit.

for example

ROW 1 Quetison 1 radiobutton1 radiobutton2 radiobutton3

ROW 2 Quetison 2 radiobutton1 radiobutton2 radiobutton3

on submit i want to findout if user checked atleast one radiobutton on each ROW

+2  A: 

for an Asp.Net ListView:

foreach(ListViewDataItem myItem in myListView.Items)
{
   RadioButton btn1 = (RadioButton)myItem.FindControl("radiobutton1");
   RadioButton btn2 = (RadioButton)myItem.FindControl("radiobutton2");
   RadioButton btn3 = (RadioButton)myItem.FindControl("radiobutton3");

   bool AtLeastOneChecked = btn1.Checked || btn2.Checked || btn3.Checked; 

}

New approach - not knowing the # of radio buttons

  foreach(ListViewDataItem myItem in myListView.Items)
{
   bool AtLeastOneChecked = false;
   foreach(Control myControl in myItem.Controls)
   {
      try
      {
         RadioButton rdoTemp = (RadioButton)myControl;
         AtLeastOneChecked = rdoTemp.Checked;
      }
      catch (Exception)
      {
          // do nothing - this probably wasn't a radio button control and errored out onthe conversion
      }
   }    
}
David Stratton
thanks, this looks promising but my problem is i do not know number of radio buttons. I only know maximum radiobutton count (which is 5)
nLL
it looks like it works even if number of radio buttons diffrent that ones in foreach loop thanks
nLL