所有单选按钮列表值的总和
我在一个页面上有 20 个 radiobuttonlists
。每个都有 4 个选项,值为 1、2、3 和 4。
我需要做的是提交表单,获取所有 radiobuttonlists
的总价值(例如 3+1+2+3+ 4...) 除以实际填写的总数(它们都不是必填字段,因此可以填写 0 到 20 之间的任何内容) - 从而获得平均值。
有没有一种简单/优雅的方法来做到这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会将 RadioButtonList 嵌入面板或其他容器控件中。然后你可以循环它的控制集合来获取所有RadioButtonList。
您想除以 RBL 的数量还是除以所选 RBL 的数量?
除以 RBL-Count 的示例,因此将未选择的计数为零,并四舍五入到下一个整数:
aspx:
并在代码隐藏中:
根据您的新信息,您需要仅计算选定的 RadioButtonLists 并完全忽略 fe RadioButtonList14,看看:
我已将
rblCount += 1
移至If rbl.SelectedIndex <> -1
-声明,此外我还添加了rbl.ID <> “RadioButtonList14”
作为忽略此 RadioButtonList 的附加限制。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.