Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3956714
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:23:56+00:00 2026-05-20T02:23:56+00:00

I have 20 radiobuttonlists on a page. Each has 4 options with values 1,

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T02:23:56+00:00Added an answer on May 20, 2026 at 2:23 am

    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:

       <asp:Panel ID="OptionPanel" runat="server">
            <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
                <asp:ListItem Text="1" Value="1"></asp:ListItem>
                <asp:ListItem Text="2" Value="2"></asp:ListItem>
                <asp:ListItem Text="3" Value="3"></asp:ListItem>
                <asp:ListItem Text="4" Value="4"></asp:ListItem>
            </asp:RadioButtonList>
            <!-- and so on ... -->
        </asp:Panel>
        <asp:Button ID="BtnCalculate" runat="server" Text="calculate average value" />
        <asp:Label ID="LblResult" runat="server" Text=""></asp:Label>
    

    and in codebehind:

        Protected Sub BtnCalculate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BtnCalculate.Click
            Dim rblCount As Int32
            Dim total As Int32
            Dim avg As Int32
            For Each ctrl As UI.Control In Me.OptionPanel.Controls
                If TypeOf ctrl Is RadioButtonList Then
                    rblCount += 1
                    Dim rbl As RadioButtonList = DirectCast(ctrl, RadioButtonList)
                    If rbl.SelectedIndex <> -1 Then
                        Dim value As Int32 = Int32.Parse(rbl.SelectedValue)
                        total += value
                    End If
                End If
            Next
            If rblCount <> 0 Then
                avg = Convert.ToInt32(Math.Round(total / rblCount, MidpointRounding.AwayFromZero))
            End If
            Me.LblResult.Text = "Average: " & avg
        End Sub
    

    According to youre new informations that you need to count only the selected RadioButtonLists and ignore f.e. RadioButtonList14 completely, have a look:

    If rbl.SelectedIndex <> -1 AndAlso rbl.ID <> "RadioButtonList14" Then
       Dim value As Int32 = Int32.Parse(rbl.SelectedValue)
       total += value
       rblCount += 1 'count only the selected RadiobuttonLists'
    End If
    

    I have moved rblCount += 1 into the If rbl.SelectedIndex <> -1-Statement, besides i’ve added rbl.ID <> "RadioButtonList14" as additional restriction to ignore this RadioButtonList.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a login.jsp page which contains a login form. Once logged in the
hi i need to modify my code a little bit. i have a page
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have two radiobuttonlist and one checkboxlist on the page. Ideally based on the
Good Morning All, I have loaded over 1,300 blurbs into my client's database with
I have a RadioButtonList on my .aspx page and I load it in the
I have a RadioButtonList in an UpdatePanel. Say I click the second button (value
I have a page that add Items to RadioButtonList with this code : Protected
I have a table cell with a RadioButtonList . When each item is selected,
I have a RadioButtonList which has AutoPostBack set to True and is being handled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.