I have 20 radiobuttonlists
on a page. Each has 4 options with values 1, 2, 3 and 4.
What I need to do is on submitting the form, get the total value of all the radiobuttonlists
(eg 3+1+2+3+4...) divided by the total number that have actually been filled in (none of them are required fields so anything from 0 to 20 of them could have been filled in) - hence getting an average value.
Is there an easy / elegant way of doing this?
I would embed the RadioButtonLists in a Panel or an other Container-control. Then you can loop its control-collection to get all RadioButtonLists.
Do you want to divide by the number of RBL's or by the number of selected RBL's?
Example that divides by RBL-Count,hence counts non selected as zero, and rounds to next integer:
aspx:
and in codebehind:
According to youre new informations that you need to count only the selected RadioButtonLists and ignore f.e. RadioButtonList14 completely, have a look:
I have moved
rblCount += 1
into theIf rbl.SelectedIndex <> -1
-Statement, besides i've addedrbl.ID <> "RadioButtonList14"
as additional restriction to ignore this RadioButtonList.